linnovate / mean

The MEAN stack uses Mongo, Express, Angular(6) and Node for simple and scalable fullstack js applications
http://mean.io
12.12k stars 3.45k forks source link

res.download - file extension lost #1943

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi,

I am using json2csv lib to generate file on the server and then using res.download prompting user to download it.

I see file downloaded as blob and without file extension.

https://user-images.githubusercontent.com/1841956/53301009-d0622c00-3873-11e9-9997-f235996f6342.png

Here is my code:

res.setHeader('Content-type', 'text/csv'); res.download(filepath, filename, function () { fs.unlinkSync(filepath); });

filename - download.pdf filepath - full path with filename

ghost commented 5 years ago

Issue fixed.

Used ngx-filesaver in angular front and save file. https://www.npmjs.com/package/ngx-filesaver