I have an application in nodejs / express that creates a PDF file and passes it in response. When I execute a request through curl or wget, downloading files is just fine.
When I execute a request in a browser, the file does not load correctly. It is interesting that the file size is much larger (when downloading using wget / curl - 59 thousand, but when downloading in the browser - 101 thousand)
Here is the snippet that generates the response:
fs.readFile('file.pdf', function(err, data) {
res.setHeader('Content-Disposition', 'attachment; filename=' + req.params.id + '.pdf');
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Length', data.length);
res.status(200).end(data);
});
I don’t know if I’m missing a header or if there is something in the request that I should pay attention to, this is not so, but I have no idea why this is happening. Any ideas?
source
share