I uploading 2 files that coming from on same form. I wanted to check mimetype , first one is must be 'image/png' and second one is must be 'video/mp4'. If first file is not png and second one is not mp4 my error working correctly. My problem is if first mimetype is not true but second file mimetype is true second file uploading on folder. I want to block 2 files even if one of them mimetype different. My code:
app.use(
multer({
storage: storage,
fileFilter: function (req, file, cb) {
if (file.fieldname=='first') {
if(file.mimetype !== 'image/png'){
return cb(null, false, new Error('wrong'));
}
}
if (file.fieldname=='second') {
if(file.mimetype !== 'video/mp4'){
return cb(null, false, new Error('wrong'));
}
}
cb(null, true);
}
}).fields([
{ name: 'first', maxCount: 1 },
{ name: 'second', maxCount: 1 }
]),
);