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

214
Vistas
Upload the image only after validating the image size in express js

Here is my code to check the image size and width that matches the criteria

im.identify(req.files.image,function (err,features) {      
   //console.log(features);                                
    if(features.width<1000){                               
        console.log('need bigger size');                   
    }                                                      
  });  
 //upload code here
 beginUpload();

Since its asynchronous the beginUpload() function is invoked early so how can i check the image size synchronously. ie i want to upload the image that pass the size criteria

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Call your function in a promise.

When your identify() function is done, the promise (then()) will be execute.

Try this :

im.identify(req.files.image,function (err,features) {      
    //console.log(features);                                
    if(features.width<1000){                   
        console.log('need bigger size');
        //stop the function to don't execute then()
        return false;                 
    }                                                   
}).then(function() {
    //upload code here
    beginUpload();
});
about 4 years ago · Santiago Trujillo Denunciar

0

@Maitre Manuel correctly notes that the UI can implement a Promise to ensure the asynchronous validation happens before posting.

This SO question discusses some of the code you can use for the check itself. Eg, to determine image width on the client side before posting.

about 4 years ago · Santiago Trujillo Denunciar
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