I need to resize my images before I upload them to s3 (amazon). I tried this function but it\'s not working.
Here is the function that uploads the image.
My
You seem to be lacking basic concepts like "before" and data flow, but I'll try anyway.
You need to insert something between reading the file and uploading to S3. A convert process would seem like a good idea.
var args = ['beach_life-normal.jpg', '-resize', '200x200>', 'JPEG:-']
var convert = child_process.spawn('convert', args);
var s3 = new AWS.S3();
s3.putObject({
Bucket: 'adinoauploadefile',
Key: 'beach_life-normal.jpg',
Body: convert.stdout
},
// ...
I'll leave the error handling, etc. to you.
In your example you're saving the image to S3 (s3.putObject
) before resizing it (im.resize
). Move the resize function before the put.
You're also not passing the image to the resize function; you'll need something like
im.resize(fileStream, { // pass in the image
height:100,
width: 200
}, function(err, stdout, stderr){
if (err) throw err;
console.log('resized image to fit within 200x200px');
});
Check the docs for the library you're using for the correct syntax.
use this code.
im.convert(['kittens.jpg', '-resize', '25x120', 'kittens-small.jpg'],
function(err, stdout){
if (err) throw err;
console.log('stdout:', stdout);
});
In place of kittens.jpg ,you can give path of image or in your case you can use fileStream and kittens-small.jpg will be name of resized image name.