在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

最佳答案

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


应该:

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

关于node.js - “image-min”在 Node js的“multer”中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36349278/

10-11 12:34