I am using Meteor on Server side where I used Method Calls to return data.
So there I am trying to upload file to AWS S3 Bucket synchronously.
Here is a sample code:
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;
},
});
Now here I want to return the response I got from AWS SDK Callback. How can I make this upload synchronously?