Can't get multer filefilter error handling to work
fileFilter function has access to request object (req). This object is also available in your router.
Therefore in fileFitler you can add property with validation error or validation error list (you can upload many files, and some of them could pass).And in router you check if property with errors exists.
in filter:
fileFilter: function (req, file, cb) { if (file.mimetype !== 'image/png') { req.fileValidationError = 'goes wrong on the mimetype'; return cb(null, false, new Error('goes wrong on the mimetype')); } cb(null, true);}
in router:
router.post('/upload',function(req,res){ upload(req,res,function(err) { if(req.fileValidationError) { return res.end(req.fileValidationError); } )})}