在 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 未定义