TF6760-File-Download is a sample project for downloading files over the HTTPS/REST protocol. This can be used to retrieve files from AWS S3 Buckets and many other sources.
Services such as AWS S3 have a request limitation of 1MB per request, and downloading files >1MB over a single command is not possible. There are usually ways around this within the services environment, such as signed links for S3. However, signed links only last for a specific amount of time and are not as friendly to work with.
Instead of a single large request, this project utilizes a "chunker" to break the larger file into smaller segments. By default, the FB's constant CHUNK_SIZE is set to 1000kb to avoid going over a request limitation.
CHUNK_SIZE : ULINT := 1000*1024; //1000*1024 = 1000Kb Chunk size
The file download FB processes data as follows:
- Completes HTTPS/REST request for header data only
- Looks for the 'Accept-Ranges' and 'Content-Length' fields
- Opens file on hard disk for writing in binary mode
- Loops through HTTPS/REST requests of CHUNK_SIZE until 'Content-Length' is reached
- Closes and saves file
There is also a status feedback that is fed out of the FB in the form of a structure via P_Status. It will relay if the process is complete/error/busy and also a 0-100% download progress.
This sample is created by Beckhoff Automation LLC., and is provided as-is under the Zero-Clause BSD license.
Should you have any questions regarding the provided sample code, please contact your local Beckhoff support team. Contact information can be found on the official Beckhoff website at https://www.beckhoff.com/en-us/support/.
The following components must be installed to run sample code:
- TE1000 TwinCAT 3 Engineering version 3.1.4024.50 or higher