我正在使用 multer 将图像上传到服务器并使用 imagemin 来压缩图像。但是当我无法压缩图像时。
app.post('/upload',(req,res)=>{
upload(req,res,(err)=>{
if(err){
res.render('picupload',{
msg: err
});
}else{
if(req.file == undefined){
res.render('picupload',{
msg: 'Error: No File selected!'
});
} else{
console.log(req.file);
imagemin([ `uploads/${req.file.filename}`], 'uploads/compressed', {
plugins: [
imageminJpegtran(),
imageminPngquant({quality: '65-80'})
]
}).then(files => {
console.log(files);
});
res.render(pathjoin13,{
file: `uploads/${req.file.filename}` ,
file_comp: `uploads/compressed/${req.file.filename}`
});
}
}
});
});