I have this piece of code in a Node.js + Express application to serve ZIP files containing images to the user when visiting a /download
route.
res.setHeader('Content-type', 'application/zip');
let fileStream = fs.createReadStream(pathToZip);
fileStream.pipe(res);
fileStream.on('error', function (error) {
/** error handling happening here **/
});
fileStream.on('close', function () {
/** Close Filestream and delete ZIP File from Server **/
fileStream.destroy();
fs.unlink(path);
});
Downloading the files work in Chrome, Safari and even IE (latest versions). When trying to download with Firefox (Mac + Windows, FF Quantum 57.0.4) no download prompt appears.
The Firefox network inspector shows me a successful XHR request for the /download
route with a long string of characters and numbers as the response (Charactercount for the response: 2097152 characters).
Am I missing something?
Thanks in advance!