"File does not exist" 在强大的上传中使用 compress_image
"File does not exist" when using compress_image on formidable upload
我正在尝试使用 compress_images module on a file uploaded using formidable,但收到“文件不存在”的错误消息。任何想法为什么?这是来自 routes.js:
的代码
app.post('/uploadPicture', isLoggedIn, function(req, res) {
const form = formidable({ multiples: true });
form.parse(req, (err, fields, files) => {
if (err) {
next(err);
return;
}
compress_images(URL+files.someExpressFiles.path+"/"+files.someExpressFiles.name
, "public/build"+files.someExpressFiles.path+"/",
{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);
res.json(statistic);
console.log('-------------');
});
res.json({ fields, files });
});
});
我通过修复路径和保留文件扩展名解决了这个问题。这是工作代码:
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 });
});
});
我正在尝试使用 compress_images module on a file uploaded using formidable,但收到“文件不存在”的错误消息。任何想法为什么?这是来自 routes.js:
的代码app.post('/uploadPicture', isLoggedIn, function(req, res) {
const form = formidable({ multiples: true });
form.parse(req, (err, fields, files) => {
if (err) {
next(err);
return;
}
compress_images(URL+files.someExpressFiles.path+"/"+files.someExpressFiles.name
, "public/build"+files.someExpressFiles.path+"/",
{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);
res.json(statistic);
console.log('-------------');
});
res.json({ fields, files });
});
});
我通过修复路径和保留文件扩展名解决了这个问题。这是工作代码:
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 });
});
});