如何使用新的Express-validator版本6.6检查图像上传

问题描述

我尝试进行一些图像验证并获得此错误

TypeError:无法读取null的属性“图像”

这是我的代码

router.post(
  "/add-product",[check("price","Preis muss einen Wert haben").isDecimal()],[check("image","Du musst ein Image uploaden").custom(function(value!!!,filename){;
    console.log(222,filename);
    var extension = (path.extname(filename)).toLowerCase();
    switch(extension){
      case '.jpg':
        return 'jpg';
      case '.jpg':
        return 'jpeg';
      case '.png':
        return 'png';
      case '':
        return 'jpg';
      default:
        return false;
    }
  })],function (req,res) {
    var imageFile = typeof req.files.image !== "undefined" ? req.files.image.name : "";
...

I checked this documentation for help:

https://express-validator.github.io/docs/custom-validators-sanitizers.html

Thanks for Help

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)