I am having some problems uploading my image from a form to my s3 bucket. At present part of the image gets uploaded, so for example 19kb instead of the full 272kb, if i try and open the image from within my bucket it's broken
app.post('/admin/addClub', (req, res) => {
if (!req.user) {
res.redirect('/admin');
return;
}
// Upload image to S3
var s3Bucket = new AWS.S3( { params: {Bucket: process.env.AWS_BUCKET, Key: process.env.AWS_ACCESS_KEY_ID} } )
var data = { Key: req.body.imageBanner, // file from form
Body: req.body.imageBanner, // Not sure here
ACL: "public-read",
ContentType: helper.getContentTypeByFile(req.body.imageBanner)
};
s3Bucket.putObject(data, function(err, data){
if (err)
{ console.log('Error uploading data: ', data);
res.redirect('/admin/main');
} else {
console.log('succesfully uploaded the image!');
res.redirect('/admin/main');
}
});
Can anybody advise what i need to pass through for the Body key? as i think this must be my issue
Thanks
res.redirect('/admin/main');could be outside the if.