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

255
Vistas
JavaScript devuelve valores del método .onload del objeto de imagen

Estoy llamando a getFileDimensions en otro archivo. Necesito este método para devolver valores que están dentro del método .onload() . Los valores son correctos, solo necesito devolverlos usando la función externa.

 export const getFileDimensions = file => { var reader = new FileReader(); //Read the contents of Image File. reader.readAsDataURL(file); var width, height = null reader.onload = function (e) { //Initiate the JavaScript Image object. var image = new Image(); //Set the Base64 string return from FileReader as source. image.src = e.target.result; //Validate the File Height and Width. image.onload = function () { console.log("Image loaded", this.width, this.height) height = this.height; width = this.width; return { width: this.width, height: this.height } }; return { width: width, height: height } }; return { width: width, height: height } }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Intenta usar Promesas

 export const getFileDimensions = async (file) => { var reader = new FileReader(); //Read the contents of Image File. reader.readAsDataURL(file); var width, height = null; const result = await new Promise((resolve) => { reader.onload = function (e) { //Initiate the JavaScript Image object. var image = new Image(); //Set the Base64 string return from FileReader as source. image.src = e.target.result; //Validate the File Height and Width. image.onload = function () { console.log("Image loaded", this.width, this.height); height = this.height; width = this.width; resolve({ width: this.width, height: this.height }); }; }; }); return result; };
about 4 years ago · Juan Pablo Isaza 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