小编Gau*_*ith的帖子

将 Ajax 响应下载为 zip 文件?

我正在尝试将多个图像下载为 zip 文件。由于我使用的是 Azure blob,因此我首先列出了所有 blob,然后使用Archiver对其进行压缩,并使用管道函数将其发送到客户端。但我将 zip 作为原始文件获取,但未下载。我正在使用 Node js + Express。服务器端脚本:

    function zipURLs(urls, outStream) {
  var zipArchive = archiver.create('zip');

  async.eachLimit(urls, 3, function(url, done) {
    console.log(url);
    var stream = request.get(url);

    stream.on('error', function(err) {
      return done(err);
    }).on('end', function() {
      return done();
    });

    // Use the last part of the URL as a filename within the ZIP archive.
    zipArchive.append(stream, { name : url.replace(/^.*\//, '') });
  }, function(err) {
    if (err) throw err;
    zipArchive.finalize();
    zipArchive.pipe(outStream);


  });
}
Run Code Online (Sandbox Code Playgroud)
var data = {}; …
Run Code Online (Sandbox Code Playgroud)

javascript zip blob node.js express

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

blob ×1

express ×1

javascript ×1

node.js ×1

zip ×1