And*_*sen 9 amazon-s3 node.js aws-sdk
我正在尝试将图像上传到S3但是当我调用s3.putObject(params,callback)时,我的回调永远不会被调用,也不会记录任何错误.
这是相关的代码:
var params = {
Key: key,
Body: imageData,
ContentLength: imageData.byteCount,
ContentType: contentType,
};
this.s3.putObject(params, function(err, data) {
console.log('here');
if (err) {
callback(err);
return;
}
callback(null, key);
});
Run Code Online (Sandbox Code Playgroud)
params是 {
Key: 'e2f99bf3a321282cc7dfaef69fe8ca62.jpg',
Body: {imageData parsed from request using node-multiparty},
ContentLength: 27802,
ContentType: 'image/jpeg',
}
我已经验证this.s3是有效的,并且this.s3.ObjectObject的typeof按预期运行.
如果此代码用于lambda函数,则需要在putObject的回调函数中添加context.done(),如下所示:
s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
context.done();
});
Run Code Online (Sandbox Code Playgroud)
这会强制执行等待回调在退出之前完成.为此,您还需要从主处理程序中删除任何context.succeed或context.done(如果有的话).
| 归档时间: |
|
| 查看次数: |
3592 次 |
| 最近记录: |