Download Files
This page shows you how to download a file using an API and S3 datasource.
Prerequisites
- Access to a cloud platform with API endpoints.
- A Table widget connected to a fetch query that has the data you want to download.
Download file using public URL
To download a file using the file URL, follow these steps:
-
Configure the download API and specify the request method (GET).
-
Add a new column to the Table widget and set its Column Type to Button.
-
Set the Button widget's onClick event to download a file corresponding to a triggerd row using the download() function.
Example:
{{download(tbl_fileDetails.triggeredRow.file_url,tbl_fileDetails.triggeredRow.file_name)}}
In the above example,
tbl_fileDetails
is the Table name,file_url
andfile_name
are the column names. -
To test the download, click any row on the table.
Download file using authenticated URL
Authenticated URLs require a different approach since they cannot be opened directly in the browser. To download a file with authentication, you should fetch the file data, and then download the file using the retrieved data. To download a file using the file data, follow these steps:
-
Configure the download API and specify the request method (GET).
-
In Headers, add the key
content_type
and enter the MIME type as its value. For example:application/pdf
-
Add a new column to the Table widget and set its Column Type to Button.
-
Set the Button widget's onClick event to download a PDF file from the API using the download() function.
Example:
{{fetch_files.run(()=>{download(fetch_files.data,"filename.pdf")})}}
To decode an encoded file content, use the JavaScript
atob()
method.Example:
{{fetch_files.run(()=>{download(atob(fetch_files.data),"filename.pdf")})}}
-
To test the download, select any row on the table.