How to Send Files to the Client
Express provides a handy method to transfer a file as an attachment: Response.download()
.
Once a user hits a route that sends a file using this method, browsers will prompt the user to download.
The Response.download()
method allows you to send a file attached to the request, and the browser, instead of showing it in the page, will save it to disk.
In the context of an app:
You can set the file to be sent with a custom filename:
This method provides a callback function which you can use to execute code once the file has been sent:
Was this helpful?