我正在尝试将多个图像下载为 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)