arisalexis arisalexis - 5 months ago 36
Node.js Question

Rename a stream in node.js before sending it to client

I have the following code in an expressjs route:

readstream.on('error', function (err) {
console.log('An error occurred!', err);
throw err;


I want to change the filename because currently it is a random id (it's stored like that in my database).


Set a header before sending it --

res.header('Content-Disposition', 'attachment; filename="new file name.pdf"');