1 回答
TA贡献1843条经验 获得超7个赞
我通过修复路径并保留文件扩展名解决了这个问题。这是工作代码:
app.post('/uploadPicture', isLoggedIn, function(req, res) {
const form = formidable({ multiples: true
, keepExtensions: true
, uploadDir: uploadDir
});
form.parse(req, (err, fields, files) => {
if (err) {
next(err);
return;
}
var mypath = files.someExpressFiles.path;
compress_images(mypath
, "public/build/",
{compress_force: false, statistic: true, autoupdate: true}, false,
{jpg: {engine: 'mozjpeg', command: ['-quality', '60']}},
{png: {engine: 'pngquant', command: ['--quality=20-50']}},
{svg: {engine: 'svgo', command: '--multipass'}},
{gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}}
, function(error, completed, statistic){
console.log('-------------');
console.log(error);
console.log(completed);
console.log(statistic);
console.log('-------------');
});
res.json({ fields, files });
});
});
添加回答
举报