I am uploading image files using s3. But whenever I try to download using the URL as well as from the s3 console will download the image file. But, it will not visible to the image viewer. It just shows an incompatible file type.
myS3Function.uploadFile(request.body.fileName, request.files.myFileData, "image_folder").then(filename => {
//success
})
const AWS = require('aws-sdk');
const s3 = new AWS.S3({
region: process.env.REGION
});
exports.uploadFile = (filename, data, folderName) => {
return new Promise((resolve, reject) => {
const params = {
Bucket: process.env.AWS_S3_BUCKET,
Key: folderName+'/'+filename,
Body: data.data,
ACL:'public-read',
ContentType: "image/jpeg"
};
s3.upload(params, function(s3Err, data) {
if (s3Err) reject(s3Err)
console.log(`File uploaded successfully at ${data.Location}`)
resolve(`${data.Location}`)
});
});
}
I uploaded files using postman now as form data. I can see text files uploaded using this code correctly. Then why do images have the issue? Also, images and pdf actual file size is increased a little bit.
The image I am getting is showing the error It appears that we don’t support this file format.
I tried by replace the upload code to s3 with local file upload using express. The issue still exists.
I refer Upload image to s3, image broken AND File uploaded to s3 but it doesn't open(corrupted) but no use.
I have two questions
-
Is there any way to fix this?
-
If not, which is the best latest way I need to choose from the below?
- Amplify s3 upload
- Signed url upload
- Or any other latest