Download Files Using API
This page shows you how to download a file using an API using PDF as the file format.
Prerequisites
Download file using URL
To download a file using the file URL, follow these steps:
In the API configuration, specify the request method (GET) and provide your API URL, including any necessary path.
Configure the Table data property of the Table widget to bind the response of the API using
{{download_image.data}}
wheredownload_image
is the name of the query.Set the widget's onRowSelected event to download a file corresponding to a selected row by pasting the following code where
imageCatalog
is the name of the Table widget:{{download_image.run(()=>download(imageCatalog.selectedRow.url,imageCatalog.selectedRow.fileName))}}
To test the download, click on any row on the table.
Download file using file data
To download a file using the file data, follow these steps:
In the API configuration, specify the request method (GET) and provide your API URL, including any necessary path.
In Headers, add the key
content_type
and enter the MIME type as its value. For example:application/pdf
Configure the Table data property of the Table widget to bind the response of the API using
{{list_files.data}}
wherelist_files
is the name of the query.Set the widget's onRowSelected event to download a PDF file from the API using the following code:
{{list_files.run(()=>{download(list_files.data,"filename.pdf")})}}
To decode an encoded file content, use the JavaScript
atob()
method.For example:
{{list_files.run(()=>{download(atob(list_files.data),"filename.pdf")})}}
To test the download, click on any row on the table.