我正在使用Node JS开发AWS Lambda函数。这样做是生成上传到s3的照片的多个缩略图版本。我在一个处理程序中保存多个对象。
这是将多个对象上传回s3的主要功能。
function runWaterfall(srcBucket, srcKey, dstBucket, dstKey, imageType, lastChars, callback)
{
// Download the image from S3, transform, and upload to a different S3 bucket.
async.waterfall([
function download(next) {
// Download the image from S3 into a buffer.
s3.getObject({
Bucket: srcBucket,
Key: srcKey
},
next);
},
function transform(response, next) {
//Code for resizing goes here
},
function upload(contentType, data, next) {
// Stream the transformed image to a different S3 bucket.
//First common thumb image.
s3.putObject({
Bucket: dstBucket,
Key: dstKey,
Body: data,
ContentType: contentType
},
function(err, data){
//Second area resized image
s3.putObject({
Bucket: dstBucket,
Key : first_path_seg + "/" + second_path_seg + "/" + file_pure_name + ".607." + lastChars,
Body : resizedImagesBuffer[1]
},
function(sec_err, sec_data){
s3.putObject({
Bucket: dstBucket,
Key : first_path_seg + "/" + second_path_seg + "/" + file_pure_name + ".502." + lastChars,
Body : resizedImagesBuffer[2]
},
next);
});
});
}],
function (err) {
if (err) {
console.error(
'Unable to resize ' + srcBucket + '/' + srcKey +
' and upload to ' + dstBucket + '/' + dstKey +
' due to an error: ' + err
);
} else {
console.log(
'Successfully resized ' + srcBucket + '/' + srcKey +
' and uploaded to ' + dstBucket + '/' + dstKey
);
}
callback(null, "message");
}
);
}
当我在AWS控制台中测试我的功能时,它运行正常。它正在为上传到s3的照片生成多个缩略图版本。但我写了一个PHP脚本,将照片上传到s3。但是当从我的PHP脚本上传照片时,lambda函数只生成一个缩略图。请看这段代码。
function upload(contentType, data, next) {
// Stream the transformed image to a different S3 bucket.
//First common thumb image.
s3.putObject({
Bucket: dstBucket,
Key: dstKey,
Body: data,
ContentType: contentType
},
function(err, data){
//Second area resized image
s3.putObject({
Bucket: dstBucket,
Key : first_path_seg + "/" + second_path_seg + "/" + file_pure_name + ".607." + lastChars,
Body : resizedImagesBuffer[1]
},
function(sec_err, sec_data){
s3.putObject({
Bucket: dstBucket,
Key : first_path_seg + "/" + second_path_seg + "/" + file_pure_name + ".502." + lastChars,
Body : resizedImagesBuffer[2]
},
next);
});
});
}
该代码将三张照片一个接一个地异步保存回s3存储桶。但只保存了第一张照片。问题是什么?当我使用AWS控制台测试函数时为什么它按预期工作?为什么当我从PHP上传照片时它只生成一个缩略图?我该如何解决?