Skip to content
Advertisement

How to validate multiple file uploads with multer expressjs

I have a problem with express.js and multer when I try to upload 2 valid images and 1 example pdf to validate is all images, it will upload that two images into a folder, and then it will throw the error for pdf that is an invalid format, can I somehow validate first all images and then do the upload to folder or throw the error is something is wrong here is my code

JavaScript
JavaScript

I want to validate all uploaded files before insert to a folder, server, etc…

Advertisement

Answer

I found a solution by throwing the error in cb function in fileFilter function

JavaScript
Advertisement