Download Files from S3
This page shows you steps to download a file from an S3 datasource.
Prerequisites
- An Amazon S3 bucket in one of the AWS Regions.
- App connected to S3 datasource.
- A Table widget to bind data and download files.
- Make sure the server from which the file is retrieved is CORS-enabled and returns the required headers. To prevent download blocks, files must be served over HTTPS. For instructions to add a CORS configuration to your S3 bucket, see CORS configuration.
Download single file from S3
To configure the S3 query to fetch all the files from a bucket and download a file using file data, follow these steps:
- In Queries/JS, click the + Add a new query/JS Object and rename it to - list_files.
- Select your S3 datasource. 
- Select List files in bucket from Commands. 
- Configure the Table data property of the widget to bind the response of the - list_filesquery using- {{list_files.data}}.
- Set the widget's onRowSelected event to download a file corresponding to a selected row by pasting the following code where - s3_files_detailsis the name of the Table widget:- {{download(s3_files_details.selectedRow.url,s3_files_details.selectedRow.fileName.split("/").pop())}}}
- To test the download, click on any row on the table. 
Download multiple files from S3
To download multiple files from an S3 bucket, follow these steps:
- Drag and drop a Button widget on to the canvas and rename it to - Download all.
- In Queries/JS, click + Add a new query/JS Object, and then select New JS Object. 
- Rename it to - bulkDownload.
- Paste the following code to add a JavaScript function to download the files: - export default {
 async downloadFiles (url, fileName) {
 download(url, fileName.split("/").pop());
 }}
- Set the widget's onClick event to download all the files from the S3 bucket by pasting the following code: - {{ListFiles.data.forEach(fileobject => bulkDownload.downloadFiles(object.signedUrl,object.fileName))}}
- To test the download, click the - Download allbutton.
