res.attachment(). Resource interpreted as Document but transferred with MIME type text/csv: "http://localhost:3000/post"

Trying to trigger a download of the file.

res.attachment('./public/uploads/name-1540993539785.csv')

File is downloaded, but its content is just "uploads/name-1540995323357.csv" instead of real data.

Got an warning in console:

Resource interpreted as Document but transferred with MIME type text/csv: "http://localhost:3000/post".

728x90

1 Answers res.attachment(). Resource interpreted as Document but transferred with MIME type text/csv: "http://localhost:3000/post"

What you probably want is res.download instead

res.attachment just sets the Content-Disposition header field to “attachment” and the Content-Type to the determined type. res.download also sends the file in question.

5 months ago