Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda