Reputation: 51
I have three files, I have to zip and send, currently I am using archiver to zip them. I am trying to download the .zip file from express js. It prefectly works for text files, apparently it works for zip files even. but I can't see any data in the zip file after I download, it will be just like an empty text file
res.status(200).sendFile('./ABC.zip');
and it is a get request. tried setting
res.set('Content-Disposition', 'attachment; filename=file.zip');
res.set('Content-Type', 'application/zip');
But didn't help. do I need to set few more parameters for response object..?? please help
Upvotes: 1
Views: 1859
Reputation: 155
const downloadName = `${Date.now()}.zip`;
const data = zip.toBuffer();
res.set('Content-Type','application/octet-stream');
res.set('Content-Disposition',`attachment; filename=${downloadName}`);
res.set('Content-Length',data.length);
res.send(data);
Upvotes: 1