2
我已经使用下面的代码在nodejs中使用简单图像npm模块完成图像大小调整。如何调整图像大小并使用nodejs中的multer上传到s3并使用easy-image npm模块?
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);
}
}
我已经有了成功的产出。 然后,我已经使用下面的代码将多张图片上传到了s3。
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);
});
现在我的问题是,如何上传到S3,然后上传调整后的图像到S3之前调整图像大小?
我也试过使用multer-imager模块。
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
})
但它不工作。 'req.file'中的 我没有定义。?
为什么不使用https://www.npmjs.com/package/multer-imager? –
看看我更新的问题@stdob – Jagadeesh