Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
How to make multiple file validation on multer

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 }
  ]),
);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!