I have done resizing of an image using easy image npm module in nodejs using the below code.
var easyimg = require('easyimage');
easyimg.rescrop({
src:'1.jpg', dst:'/var/www/html/bangalore.jpg',
width:100, height:100
}),function(image,err){
// console.log('Resized and cropped: ' + image.width + ' x ' + image.height);
if(image){
console.log(image);
}
else{
console.log(err);
}
}
I have got successfull output. Then i have uploaded my image to s3 using the below code with multer.
var storage = multerS3({
s3: s3,
bucket: 'my_bucket_name',
key: function (req, file, cb) {
console.log(file);
file_name = file.originalname;
var newFileName = Date.now() + "-" + file.originalname;
cb(null, newFileName);
}
});
var upload = multer({storage: storage}).single('profileImage');
upload(req, resq, function (err,res,response) {
console.log(response);
});
Now my question is how to resize an image before uploading to s3 and then uploading the resized image to s3?
I have also tried using multer-imager module.
var transfer = imager({
secretAccessKey: 'secretAccessKey',
accessKeyId: 'myaccesskey',
dirname:'avatar',
bucket: 'my_bucket',
region:'myregion',
key: function (req, file, cb) {
console.log(file);
file_name = file.originalname;
var newFileName = Date.now() + "-" + file.originalname;
cb(null, newFileName);
console.log(newFileName);
}, //
gm: { // [Optional]: define graphicsmagick options
width: 200, // doc: http://aheckmann.github.io/gm/docs.html#resize
height: 200,
options: '!',
format: 'png' // Default: jpg
}
});
var upload = multer({storage: transfer}).single('myimage');
upload(req, resq, function (err,res,response) {
console.log(req.file); //i am getting this as undefined
})
But it doesnt work. in 'req.file' i am getting undefined.?
multer
,aws-sdk
andsharp
. Here's a full example of how to do it. https://mcmap.net/q/1478275/-multer-s3-with-sharp-upload-and-resize – Pierides