I am using aws-sdk for my node js project, where I am sending an image HTTP POST to a node js server using a curl command
curl -X POST --data @/Users/minnaliang138/Downloads/1 -L http://54.56.22.31:3000/uploadImage
In the backend server I do
app.post('/uploadImage',function(req,res){
var bucketName = 'Images';
var keyName = 'moth.jpg';
var _data =req.body;//JSON.stringify(req.body);
var s3bucket = new AWS.S3({params: {Bucket: bucketName}});
s3bucket.createBucket(function() {
var data = {Key: keyName, Body: _data, ContentType: 'image/jpeg' };
s3bucket.putObject(data, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
})
});
I can see a file of approximately the size of image being posted uploaded on to the s3 server. However, it is corrupted.I believe
JSON.stringify(req.body)
isn't the way to convert. Can anyone suggest the right way of converting the req.body?