1

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

4

1 回答 1

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

应该:

var Imagemin = require('image-min');
于 2016-04-01T08:04:23.097 回答