问题
I have tried this code to send response zip in header, but something is missing from my side. In this I am getting response as shown in screenshot
Here is my code..
const zipPath - './test.zip'; // I have a zip with 2 files inside it (password protected)
const stat = fs.statSync(zipPath);
res.setHeader('Content-Disposition', 'attachment; filename=devices.zip');
res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Length', stat.size);
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename=test.zip',
'Content-Length': stat.size
});
let fileStream = fs.createReadStream(zipPath);
fileStream.pipe(res);
res.end();
来源:https://stackoverflow.com/questions/59280573/response-header-data-as-zip-in-node-js