“image-min”在节点js中的“multer”内不起作用

时间:2016-04-01 06:14:53

标签: node.js image-processing multer imagemin

在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

1 个答案:

答案 0 :(得分:0)

var imagemin = require('image-min');

应该是:

var Imagemin = require('image-min');