I upload an image file in the following format:
var body = fs.createReadStream(tempPath).pipe(zlib.createGzip());
var s3obj = new AWS.S3({params: {Bucket: myBucket, Key: myKey}});
var params = {
Body: body,
ACL: 'public-read',
ContentType: 'image/png'
};
s3obj.upload(params, function(err, data) {
if (err) console.log("An error occurred with S3 fig upload: ", err);
console.log("Uploaded the image file at: ", data.Location);
});
The image successfully loads into my S3 bucket (there are no error messages and I see it on the S3 console), but when I try to display it on my website, it returns a broken img icon. When I upload an image using the S3 console file downloader, I cannot open it with an error that the file is “damaged or damaged”.
If I upload the file manually using the S3 console, I can correctly display it on my website, so I'm sure that something is wrong with the way I upload.
What is going wrong?
source
share