I am using graphicMagic to resize an image before uploading it to aws s3 bucket. The code below uploads an image with 0 byte size, though the response from s3 upload is fine. The following code is what I am doing. The path is the path of the image that needs to be uploaded. The key is the hashed key to make the file name unique.
gm(path)
.resize(100,100)
.stream(function(err, stdout, stderr){
if(err){
console.log("Error resizing image. Message:",err);
}
else{
console.log(stdout);
var data = {
Bucket: 'my-bucket',
Key: key+"_thumb.jpg",
Body: stdout,
ACL: "public-read",
ContentType:"image/jpeg"
};
p1 = s3.upload(data).promise();
}
});
I think stdout is not the correct thing to do, but then how do I make it work.
Your code is fine, you're missing gm
dependencies: imagemagick
or graphicsmagick
, if one of those are missing, no error will be triggered, but you will get a 0 byte file.
Depending on your OS:
Ubuntu/Debian
sudo apt-get install graphicsmagick
# or
sudo apt-get install imagemagick
Mac OS
brew install graphicsmagick
brew install imagemagick
For windows or other OS, check: