SOLFIND
Web Lens
Portal home

download() | Appsmith

https://docs.appsmith.com/reference/appsmith-framework/widget-actions/download • 64 KB fetched
Open original page


download() | Appsmith

Skip to main content

Ask AI
Search

Ask Appsmith AI Submit message

Examples How do I install Appsmith using Docker? How do I connect to my local PostgreSQL database? How do I pass inputs from a widget to a query? How do I trigger multiple queries conditionally? How do I fix the error: This value does not evaluate to type Array<Object>?

Search

Try Appsmith

* Get Started

* Introduction

* Build Your First App

* Self Hosting

* New Installation Guides

* Manage Installation

* Upgrade Installation Guides

* Concepts

* Connect Data

* Overview

* How-to Guides

* Reference

* Datasources

* Query Settings

* Concepts

* Build Apps

* Overview

* Quickstart

* How-to Guides

* Reference

* Widgets

* Accessibility

* Theme

* Sample Apps

* Write Code

* Overview

* How-to Guides

* Reference

* Global Objects

* Global Functions

* clearInterval()

* clearStore()

* closeModal()

* copyToClipboard()

* download()

* logoutUser()

* navigateTo()

* postWindowMessage()

* removeValue()

* resetWidget()

* setTimeout()

* setInterval()

* storeValue()

* showAlert()

* showModal()

* unlistenWindowMessage()

* windowMessageListener()

* JS Libraries

* Fetch API

* Data Transformation

* JavaScript Settings

* Concepts

* Best Practices

* Manage Apps and Users

* Authentication

* Granular Access Control

* Versioning with Git

* Setup SCIM Provisioning

* Embed Appsmith

* Migrate Applications

* Audit Logs

* Branding

* External Client Portal

* Packages

* Overview

* Tutorial

* How-to Guides

* Reference

* Package Version Control

* GIT Apps with Packages Best Practices

* Code Packages

* UI Packages

* Workflows

* Overview

* Tutorial

* How-to Guides

* Reference

* Workflow Triggers

* Workflow Queries

* Workflow Functions

* Pass Parameters to Workflows

* Run History

* Troubleshooting

* Overview

* Self-hosting Errors

* Application Errors

* Product

* FAQ

* Security

* Telemetry

* Support at Appsmith

* Privacy Policy

* Release Notes

* Contribute

© 2026 Appsmith, Inc.

*

* Write Code

* Reference

* Global Functions

* download()
On this page
download()

This page provides information about the download() function, which allows you to download any data as a file to your local machine. It uses the capabilities of the downloadjs library.

Signature ​

download ( data : any , fileName : string , fileType ? : string ) : Promise

Parameters ​

Below are the parameters required by the download() function to execute:

data ​

This parameter specifies the data you want to download, which can be a URL, Query data, Blob, or any String. You can pass the data using {{}} Mustache binding, for example {{Userquery.data}} .

fileName ​

This property allows you to set the name of the file. You can specify a name or dynamically set it based on query or user data. For example, you can use Mustache binding to create a dynamic file name like {{Table1.selectedRow.id}} . If there is no filename or extension specified, the download will fail.

fileType ​

This property allows you to set the MIME content-type of the file to download. If you do not specify the file type, make sure to include the appropriate file extension in the filename property, for example, file_name.csv.
The Download action does not convert the file into a specific format; it downloads the file in its original form. If you need to change the file type, you would need to convert the data to a specific format using JavaScript before downloading.
Supported file types:

* Plain text

* HTML

* CSV

* JSON

* JPEG

* PNG

* SVG

Usage ​

Here are a few examples to navigate in different situations:

Download query data ​

If you want to download your query or JS data into a file, such as a .txt or .csv file, you can pass the query data into the function like this:

download ( UserData . data , 'UsersData.csv' , 'text/csv' ) ;

Download using URL ​

If you want to download a file from a URL, you can pass the file URL to the download() function. For example, if you have a Table widget with a column containing document URLs for each user, to download the document, you can use:

download ( UsersTable . selectedRow . documentUrl , UsersTable . selectedRow . id + '.pdf' ) ;

See Download file using authenticated URL .

Format and download data ​

If you have data in one format and need to convert it to another format before downloading, you can use JSObject to transform the data and then download it. For example, if you want to convert JSON data into a CSV file, you can create JS code like:

// Assuming userdata.data contains the JSON data from the query
const jsonData = userdata . data ;

// Convert JSON to CSV
let csvData = jsonData . map ( row => ` ${ row . id } , ${ row . name } , ${ row . email } , ${ row . country } ` ) . join ( '\n' ) ;

// Use Appsmith's download function to download the CSV file
download ( csvData , "users.csv" , "text/csv" ) ;

Download using blob ​

If you want to download data based on certain criteria, you can use a JSObject.

Example : This code retrieves PDF data, creates a Blob from it, generates a temporary URL for the Blob, and triggers a download of the PDF file named "sample.pdf".

downloadPDF : async ( ) => {
let data = getPdf . data
const blob = new Blob ( [ data ] , { type : 'application/pdf' } ) ;
const url = URL . createObjectURL ( blob ) ;
await download ( url , "sample.pdf" , "application/pdf" )
}

For files to be successfully downloaded, their contents must be served over HTTPS to prevent requests from being blocked. To prevent Cross-Origin Resource Sharing (CORS) errors, ensure that the server where the file is fetched from is CORS-enabled and returns the required headers in the response.

See Download multiple files .

See also ​

* Download Files

Was this page helpful?

Edit this page

Previous
copyToClipboard()
Next
logoutUser()

* Signature

* Usage

* See also

Links found on this page

  1. Skip to main content [direct]
  2. Try Appsmith [direct]
  3. Get Started [direct]
  4. Build Your First App [direct]
  5. Self Hosting [direct]
  6. New Installation Guides [direct]
  7. Manage Installation [direct]
  8. Upgrade Installation Guides [direct]
  9. Concepts [direct]
  10. Connect Data [direct]
  11. How-to Guides [direct]
  12. Reference [direct]
  13. Query Settings [direct]
  14. Concepts [direct]
  15. Build Apps [direct]
  16. Quickstart [direct]
  17. How-to Guides [direct]
  18. Reference [direct]
  19. Widgets [direct]
  20. Accessibility [direct]
  21. Theme [direct]
  22. Sample Apps [direct]
  23. Write Code [direct]
  24. How-to Guides [direct]
  25. Reference [direct]
  26. Global Objects [direct]
  27. Global Functions [direct]
  28. clearInterval() [direct]
  29. clearStore() [direct]
  30. closeModal() [direct]
  31. copyToClipboard() [direct]
  32. logoutUser() [direct]
  33. navigateTo() [direct]
  34. postWindowMessage() [direct]
  35. removeValue() [direct]
  36. resetWidget() [direct]
  37. setTimeout() [direct]
  38. setInterval() [direct]
  39. storeValue() [direct]
  40. showAlert() [direct]
  41. showModal() [direct]
  42. unlistenWindowMessage() [direct]
  43. windowMessageListener() [direct]
  44. JS Libraries [direct]
  45. Fetch API [direct]
  46. Data Transformation [direct]
  47. JavaScript Settings [direct]
  48. Concepts [direct]
  49. Best Practices [direct]
  50. Manage Apps and Users [direct]
  51. Granular Access Control [direct]
  52. Versioning with Git [direct]
  53. Setup SCIM Provisioning [direct]
  54. Embed Appsmith [direct]
  55. Migrate Applications [direct]
  56. Audit Logs [direct]
  57. Branding [direct]
  58. External Client Portal [direct]
  59. Packages [direct]
  60. Tutorial [direct]
  61. How-to Guides [direct]
  62. Reference [direct]
  63. GIT Apps with Packages Best Practices [direct]
  64. Code Packages [direct]
  65. UI Packages [direct]
  66. Workflows [direct]
  67. Tutorial [direct]
  68. How-to Guides [direct]
  69. Reference [direct]
  70. Workflow Queries [direct]
  71. Workflow Functions [direct]
  72. Pass Parameters to Workflows [direct]
  73. Run History [direct]
  74. Troubleshooting [direct]
  75. Self-hosting Errors [direct]
  76. Application Errors [direct]
  77. Product [direct]
  78. Security [direct]
  79. Telemetry [direct]
  80. Support at Appsmith [direct]