在node-js中,我使用multer
包来上传图片。要压缩我正在使用的图像image-min
。
var multer = require('multer');
var imagemin = require('image-min');
app.use(multer({
dest : './public/images/profiles/uploads/',
rename : function(fieldname, filename) {
return (filename.split(" ").join("")) + Date.now();
},
onFileUploadStart : function(file) {
console.log(file.originalname + ' is starting ...');
},
onFileUploadComplete : function(file) {
var imagemin = new Imagemin().src(file.path).use(compressionType);
imagemin.run(function(err, files) {
if (err) {
return next(err);
}
console.log('Files optimized successfully!');
});
console.log(file.fieldname + ' uploaded to ' + file.path);
done = true;
}
}));
当我运行我的代码时抛出错误。
var imagemin = new Imagemin()。src(file.path).use(compressionType);
ReferenceError:未定义Imagemin
答案 0 :(得分:0)
var imagemin = require('image-min');
应该是:
var Imagemin = require('image-min');