1
在node-js中,我使用multer
包來上傳圖像。壓縮我使用的圖像image-min
。「image-min」在節點js中的「multer」內不起作用
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 is not defined
變種Imagemin =要求( 'imagemin');頂部可能是?另外,您是否安裝了Imagemin? –
我已經添加了上面的行並安裝了image-min – Shanthi