我使用 yazl 创建一个包含Node.js的zip文件。您可以向其添加读取流。我正在尝试将我从get请求中检索的照片添加到zip文件中。我已经尝试了以下所有方法但是当我打开拉链时,里面没有照片。
方法1:
this.s3.getObject(params, (err, photos) => {
photos = JSON.parse(photos.Body.toString());
photos.forEach((photoUrl, i) => {
let fileName = `${jobId}/getPhotoFile${i + 1}.jpg`;
http.get(photoUrl, (response) => {
zip.addReadStream(response, fileName);
}).end();
})
方法2:
this.s3.getObject( params, (err, photos) => {
photos = JSON.parse(photos.Body.toString());
photos.forEach((photoUrl, i) => {
let fileName = `${jobId}/getPhotoFile${i + 1}.jpg`;
zip.addReadStream(http.get(photoUrl), fileName);
});
});
方法3:
this.s3.getObject(params, (err, photos) => {
photos = JSON.parse(photos.Body.toString());
photos.forEach((photoUrl, i) => {
let fileName = `${jobId}/getPhotoFile${i + 1}.jpg`;
zip.addReadStream(request.get(photoUrl), fileName);
});
});