【发布时间】:2021-05-11 10:07:11
【问题描述】:
我在服务器端使用 Meteor,我使用方法调用返回数据。
所以我正在尝试将文件同步上传到 AWS S3 存储桶。
这是一个示例代码:
Meteor.methods({
uploadImage: function (params) {
var AWS = Npm.require('aws-sdk');
AWS.config.loadFromPath(process.env["PWD"]+'/private/awss3/s3_config.json');
var s3Bucket = new AWS.S3( { params: {Bucket: 'users-profile-pictures'} } );
buf = Buffer.from(params.baseimage.replace(/^data:image\/\w+;base64,/, ""),'base64')
var data = {
Key: params.fileName,
Body: buf,
ContentEncoding: 'base64',
ContentType: 'image/jpeg'
};
s3Bucket.putObject(data, function(err, data){
if (err) {
console.log(err);
console.log('Error uploading data: ', data);
} else {
console.dir(data);
console.log('successfully uploaded the image!');
}
});
return data;
},
});
现在我想返回从 AWS 开发工具包回调中获得的响应。如何同步上传?
【问题讨论】:
-
@AnonCoward 我已经使用了 await 但它给出了语法错误意外标记
标签: node.js amazon-web-services amazon-s3 meteor async-await