【问题标题】:Trying to download zip file to client browser that was streamed from server in Express尝试将 zip 文件下载到从 Express 中的服务器流式传输的客户端浏览器
【发布时间】:2019-05-07 17:56:52
【问题描述】:

我正在使用一个名为s3-zip 的工具,它在服务器端将来自 S3 的文件压缩在一起,然后使用 Express 框架将压缩文件流式传输到客户端。我可以确认服务器端的代码工作正常,如下所示

router.get('/download', function (req, res, next) {

    const region = 'us-west-2';
    const bucket = 'my-bucket';
    const folder = 'my-folder/';
    const file1 = '85570334.jpg';
    const file2 = '85570335.jpg';
    const file3 = '85571603.jpg';

    s3Zip
        .archive({ region: region, bucket: bucket}, folder, [file1, file2, file3])
        .pipe(res)
});

这是响应在 chrome 控制台上的样子

当我在客户端获取响应并尝试将其作为 zip 文件下载到客户端浏览器时,就会出现问题。我正在使用Angular File Saver 来执行此操作。下面的 sn-p 是我尝试获取与上图对应的响应并将其下载到客户端浏览器的位置。

var blob = new Blob([res._body], {type: "application/zip"});
FileSaver.saveAs(blob, "test-new.zip");

确实会下载一个 zip 文件,但是当我尝试在我的 Mac 上打开它时出现以下错误

谁能看到导致此错误的原因以及如何解决?

【问题讨论】:

    标签: angular express stream zip


    【解决方案1】:

    啊,看起来这是与请求本身相关的问题,我没有在我的问题中显示。我添加了{responseType: ResponseContentType.Blob },之后它似乎工作了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多