You are viewing limited content. For full access, please sign in.

Question

Question

How do I download a document using API?

asked on November 29, 2023 Show version history

Given the "full path" of the document, how do you then download that file?  

 

The full path is given as a relative path such as 

"fullPath": "\\Facilities Library\\Master Plan\\2022-10-31-master-plan",

 

I found this code in the .NET sample code (below):

byte[] fileBytes = await _httpClient.GetByteArrayAsync(uri);
File.WriteAllBytes(outputPath, fileBytes);

Is that how it's done? Would I just plugin the fullpath into that uri? And then write the bytes into a file? But then, that's like reading and writing on file everytime someone downloads a file?

 

Is there another way such as an API call that returns the download link? Please help!
 

~Al

 

0 0

Replies

replied on November 30, 2023

Hi, 

Given the "full path" of the document, you could fist use this get entry by path api https://api.laserfiche.com/repository/swagger/index.html?urls.primaryName=v2#/Entries/GetEntryByPath, to get the document id.

With the document id, you could then call the export api https://api.laserfiche.com/repository/swagger/index.html?urls.primaryName=v2#/Entries/ExportEntry to download the part you need. Here's the example code for download Edoc part of a document in our sample code https://github.com/Laserfiche/lf-sample-repository-api-dotnet-srv/blob/v2/Program.cs#L237C13-L250C38.

If the file size is large and the export api gets timeout, you could use this long operation export api https://api.laserfiche.com/repository/swagger/index.html?urls.primaryName=v2#/Entries/StartExportEntry

0 0
replied on November 30, 2023

Thank you so much! 

0 0
replied on December 6, 2023

Another question about this code from the github example:

var response = await client.EntriesClient.ExportEntryAsync(new ExportEntryParameters()
{
    RepositoryId = repositoryId,
    EntryId = entryId,
    Request = request
}).ConfigureAwait(false);

var uri = response.Value;

What we are trying to do in our institution is find all the Folders and Documents in a repo (which I was able to do). We need to display all these documents on a public webpage. And they must all be downloadable; that is, they need to be a hyperlink. And documents need to be downloaded directly from our self-hosted Laserfiche server.

 

My question is mostly on the following snippet:

var uri = response.Value;

Is that the download link?  

 

(Sorry for asking further about this. I have been having Laserfiche license issues that I'm having in institution that I work for and so I have not been able to test ever since I asked the original question.  Trying to get that sorted out before I can continue testing.)

0 0
replied on December 6, 2023 Show version history

It sounds like your institution would benefit more from Laserfiche WebLink (Public Portal). Trying to make everything from the Laserfiche Repository available on a separate website seems like it would be trying to bypass licensing that is already available.

0 0
replied on December 6, 2023

I should asked first but it seems you are using self-host repository api. For self-host, we only support repository api V1 for now. The links I sent in previous reply is for V2, which is only available for cloud.

For V1, there is only one api to export the edoc part of a document, and the response is the edoc content, not a link. https://api.laserfiche.com/repository/swagger/index.html?urls.primaryName=v1#/Entries/ExportDocument

For V2, the export api response is a download link. But it's not available for self-host yet.

0 0
replied on December 6, 2023

Hi Danfeng,
 

If I remember correctly, V2 API for on-prem was slated for 2nd half of 2023 - is that still the plan? Or am I incorrect on that?

0 0
replied on December 6, 2023

Hi Jacob, 

The update for the self-hosted API Server, which will include V2 of the Repository API, has been pushed to early next year.  We should have a more accurate release schedule soon though.

 

Andrew

1 0
replied on December 6, 2023

Thanks for these info guys. I literally just finished talking to my supervisors about y'all's responses . This has really changed our project timeline a little bit. The nuances between V1 and V2 were something that were not known to them when they decided on the on-premise route

 

For the time being, we are going to embed an iframe of our Laserfiche docs(I know) until we get the V2 on-premise early next year. 

0 0
replied on February 27

I am using V1 of the API and trying to Export the imported pdf file to the LF repo. It is saving the same number of pages with empty content. Not sure why?

0 0
replied on March 22

Hi @████████ - Any update on release timeline for v2 of self-hosted API server?

0 0
replied on March 28

No update at this time, but I hope to have more clarity soon.

0 0
replied on April 26

I believe adding a parameterless constructor to the FileParameter class of V1 (Self-hosted) from your side may resolve the error below. I am getting this error while implementing a wrapper against self-hosted API V1. 

I am trying to create a new Restful API that takes FileParameter as one field of the view model class during Model Binding. 

 

System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Laserfiche.Repository.Api.Client.FileParameter'. Path: $.fileParameter | LineNumber: 49 | BytePositionInLine: 20.
 ---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Laserfiche.Repository.Api.Client.FileParameter'.
0 0
replied on May 1

We currently have no plans for releasing an update to V1 backporting this feature.

0 0
replied on May 1 Show version history

Miruna, when will the updated version of V1 be released?

0 0
replied on May 2

Jemal,

We don't have a solid release date at this time but it is a priority for us.

Andrew

0 0
replied on May 2 Show version history

Hello Andrew,

 

Thank you for your prompt reply. I appreciate it. We are using self-hosted API to import huge number of documents (in number and size) to Laserfiche repository. The best way to do this is to have a wrapper API that consumer your Self-hosted API Server version 1.1 that has been installed on our servers so that the consuming vendor app should not be dealing with those configurations. 

Specifically, the issue is the FileParameter object being not serializable from our wrapper API endpoint. We are the company that uses LF products intensively and this is important to address. 

0 0
replied on May 3 Show version history

Hi!

So for the original question "Given the "full path" of the document, how do you then download that file?":

This is possible in repository API v1. The response is not a url, but instead the document content.

This can be done using the GetEntryByPath function of the v1 API and then using the entry Id returned to get the content using the GetEdoc endpoint. Below is an example of how we use the publicly available repository API client, to get and parse the edoc content given an entry ID. You could use the same client to get the entry id given a path. In this case we parse it to a base64 string, but you can use the stream content to do whatever you would like with the file content including downloading from the browser. For v1 we do only support getting documents that have an edoc in Laserfiche. 

const exportDocumentRequest = {
  repoId: 'REPO_ID',
  entryId: Number('ENTRY_ID'),
};
const response =
  await this.selectedRepositoryClient?.entriesClient.exportDocument({
    ...exportDocumentRequest,
  });
if (response.headers && this.contentTypeExists(response.headers)) {
  const body = response?.data.stream();
  const reader = body?.getReader();
  const result: string[] = [];
  if (reader) {
    let nextChunk: ReadableStreamDefaultReadResult<Uint8Array>;
    while (!(nextChunk = await reader.read()).done) {
      const partialData: Uint8Array | undefined = nextChunk.value;
      if (partialData) {
        result.push(convertUint8ArrayToString(partialData));
      }
    }
  }
  const resultString = result.join('');
  return StringUtils.stringToBase64(resultString);
} else {
  // Entry didn't have an edoc
}

For the other question of how to upload to Laserfiche using the FileParameter. We do have an example of how we do this in our sample application which is available on GitHub. We use the same Laserfiche Repository API Client which wraps the API call for us. Uploading documents via the v1 API will create an edoc but will not generate pages.

0 0
replied on May 6 Show version history

Hi Alexandria,

Downloading the edoc from our LF server works fine. I don't have any problems with that. I am having issue when we create an API that uses the LF NuGet package Laserfiche.Repository.Api.Client and try to import documents to LF through Server API V1 (LFRepositoryAPI) that we installed under our vm servers. 

 public async Task<LFRepoResponse> ImportDocument([FromBody] ImportToLFViewModel importToLFViewModel)
 {

 }

The ImportToLFViewModel my custom class that has PostEntryWithEdocMetadataRequestFileParameter and other properties.

 

Note that the FileParameter class is part of the Laserfiche.Repository.Api.Client that is giving me a runtime error from the above .NET 8 Restful endpoint ( method) that uses FromBody attribute with view model class. We can't have more than one parameter whenever we use FromBody attribute in .NET 8 Restful API. 

 

 

0 0
replied on June 27

Hi @████████ - has a timetable for the release of v2 for on-prem API been established yet?

1 0
replied on March 27 Show version history

I believe adding a parameterless constructor to the FileParameter class of V1 (Self-hosted) from your side may resolve the error below. I am getting this error while implementing a wrapper against self-hosted API V1. 

I am trying to create a new Restful API that takes FileParameter as one field of the view model class during Model Binding. 

 

System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Laserfiche.Repository.Api.Client.FileParameter'. Path: $.fileParameter | LineNumber: 49 | BytePositionInLine: 20.
 ---> System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Laserfiche.Repository.Api.Client.FileParameter'.
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.