Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Express 具有不同文件大小限制的多个多字段_Express_Limit_Multer_Filefield - Fatal编程技术网

Express 具有不同文件大小限制的多个多字段

Express 具有不同文件大小限制的多个多字段,express,limit,multer,filefield,Express,Limit,Multer,Filefield,我在做特快js multer。我上传了多个带有格式验证和大小限制的文件字段。 现在,我试图在fileFilter或multer limits中对每个文件字段设置限制,但对不同的文件字段无效。 如何在multer中上载具有不同文件大小限制的文件 const storage = multer.diskStorage({ destination: function(req, file, cb) {

我在做特快js multer。我上传了多个带有格式验证和大小限制的文件字段。 现在,我试图在fileFilter或multer limits中对每个文件字段设置限制,但对不同的文件字段无效。 如何在multer中上载具有不同文件大小限制的文件

const storage = multer.diskStorage({
                     destination: function(req, file, cb) {
                                      cb(null, './public/images/');
                     },
                     filename: function(req, file, cb) {
                                      cb(null, file.originalname );
                     }
                });
const fileFilter = (req, file, cb) => {
  if (file.mimetype == "image/png" || file.mimetype == "image/jpg" || file.mimetype == "image/jpeg") {
      cb(null, true);
    } else if (file.fieldname === "brochurefile" && file.mimetype == "application/pdf"){
      console.log("file.buffer.byteLength === ", req.files.brochurefile[0]);
      cb(null, true);
    } else {
      cb(null, false);
      return cb({message:'Only .png, .jpg and .jpeg format allowed!'}, false);
    }
  }
const upload = multer({ storage: storage, fileFilter: fileFilter, limits: { fileSize: 2097152 }});
router.post("/post/", upload.fields([{name:'logoimage', maxCount: 1}, 
                                     {name:'collegeimage', maxCount: 1}, 
                                     {name:'bannarimage', maxCount: 1}, 
                                     {name:'brochurefile', maxCount: 1}, 
                                     {name:'collegegallary'}]);, (req,res) => {});