Download file content?
Downloading file content from a REST API involves submitting a request which would then return a file as a
file stream or
binary content. This data is then translated into a ListTYP of the type ByteTYP (
List<byte> ) in Linx. The
List<byte> must then be written to a directory using a BinaryFileWriteFNC .
To demonstrate the approach, an example request is made to the PlaceGOAT API. This API returns placeholder images of goats (this approach will walk for all file types). This is a free and open API so you can try it for yourself.
In the below example, a
GET request is made to the
This will return a 200x200 image of a goat in the form of a
file stream response is then written to a local folder location.
A sample Solution is available below for a practical demonstration .
DownloadingFiles.lsoz (4.3 KB)
To write a file from a file stream:
Set the URL to
If you debug the Process, you will notice the
Response Bodycontains a bunch of weird characters like below:
You need to convert this into a
Configure the rest.callrestendpoint Output type to be
When you debug your Process, the
Response Bodyshould be deserialized into a ListTYP object:
Add a BinaryFileWriteFNC to the Process.
This allows writing binary content as a file.
Configure the BinaryFileWrite to have a File path of a location you want i.e.
You can give the file any name you want but the extension must match the file type being downloaded (i.e. ".jpeg") or else you will have a corrupted file.
CallRESTEndpoint.ResponseBodyas the Contents
Debug the Process , once finished, take a look at the file location specified in Step 4.
If the File exists is left as the default
Append data, then the file data will be appended and will be corrupted. In order to
Increment file namein cases where the file already exists, select the appropriate option.