response header data as zip in node js

大兔子大兔子 提交于 2019-12-25 01:47:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!