我想将图像裁剪成各种尺寸并将它们上传到 AWS S3。裁剪尺寸存储在一个数组中。
我正在使用async
瀑布和series
方法来实现这一点。
async.each(crop_sizes,function (result,cb) {
async.waterfall([
/*
* Crop the images to specific size
*/
function (callback) {
gm(path)
.resize(result.width,result.height,'^')
.stream(function (err,buffer) {
console.log('cropped')
callback(null,{'buffer':buffer,'filename':filename,'s3':s3});
});
},
function (output,callback) {
var params ={
Bucket:'mybucket',
Key:'artwork-croppedimages/'+result.folder+output.filename,
Body:output.buffer
}
var options ={
partSize: 5242880, queueSize: 1
};
s3.upload(params,options,function(err, data) {
console.log("upload");
callback();
});
}
],function (err,result) {
console.log("one iteration completed");
cb();
});
},function (err,result) {
console.log("All upload complete");
});
这就是代码的执行方式:
在 中重复步骤 1 和 2 async.each
。
裁剪图像。
将裁剪后的图像上传到 AWS S3。
但上传大尺寸图片时失败。这是我得到的输出:
cropped
cropped
cropped
cropped
cropped
cropped
cropped
cropped
cropped
cropped
cropped
cropped
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
upload
one iteration completed
All upload complete
预期输出:
cropped
upload
one iteration completed
cropped
upload
one iteration completed
.....
All upload complete