arisalexis arisalexis - 1 year ago 120
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).

Answer Source

Set a header before sending it --

res.header('Content-Disposition', 'attachment; filename="new file name.pdf"');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download