Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express.js : What is the difference between res.attachment and res.download?

What is the difference between res.attachment and res.download and when to use which I am bit confused. In my case, I send my form data to the server as a JSON which will create a file out of it and respond with a download link. Which among the two: res.attachment and res.download should I use?

like image 668
Rohit Rane Avatar asked Dec 04 '16 07:12

Rohit Rane


1 Answers

The res.attachment "Sets the HTTP response Content-Disposition header field to “attachment”."

This essentially says, 'Hey, this file should be viewed as an attachment, not a webpage.'

Whereas the res.download "Transfers the file at path as an “attachment”. Typically, browsers will prompt the user for download."

Find more about each HERE

like image 176
NSTuttle Avatar answered Nov 08 '22 07:11

NSTuttle