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

364
Views
How to return files that have been filtered by multer filefilter?

I'm trying to implement multer fileFilter function and it works (it does filter files and files get uploaded) but when I set file filtering req.files becomes empty.

const extFilter = function (req, file, cb) {

    if(file.originalname.match(/^.*\.(avi|mov|mp4)$/)) cb(null, true)
    
    cb(null, false)
  
}

const upload = multer({ storage: cloudStorage, 
                        fileFilter: extFilter }).array('file')

upload(req, res, function (err) {   
                return res.status(200).send(req.files) //returns nothing
              })

Without fileFilter option set the function returns array of uploaded files.

Any ideas?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The fileFilter function was missing return before cb(null, true)

const extFilter = function (req, file, cb) {

    if(file.originalname.match(/^.*\.(avi|mov|mp4)$/)) return cb(null, true)
    
    cb(null, false)
  
}

Otherwise the files get written to the disk because of the first callback but then nothing is returned in req.files because of the second cb(null, false).

about 4 years ago · Juan Pablo Isaza Report
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!