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

387
Views
¿Cómo puedo convertir los datos que son una imagen que provienen de la API a la URL para usar en la etiqueta img en reaccionar Js?

He subido una imagen. Ahora, tengo una API de descarga que me da esta imagen como datos. La respuesta se ve así:

ingrese la descripción de la imagen aquí ingrese la descripción de la imagen aquí

el encabezado de la respuesta es así:

ingrese la descripción de la imagen aquí

Ahora el problema es que quiero mostrar esta imagen en la página web usando la etiqueta img o cualquier otra cosa posible en reaccionar js. Pasar el contenido a src attr no muestra nada. ¿Alguien tiene alguna idea? ¿Hay alguna manera posible?

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

0

Debería poder usar FileReader para convertir la respuesta al formato base64 que se puede usar en el atributo src:

 // Request was successful, get image blob const blob = await response.blob() // Convert the blob to base64 const reader = new FileReader() reader.readAsDataURL(blob) // Get the converted image and set it where needed reader.onloadend = () => { const base64Image = reader.result // Set the image to the src of the image tag or setState as you need }
about 4 years ago · Juan Pablo Isaza Report

0

Esto también funcionó para mí además de la respuesta anterior:

 const fetchImage = async () => { fetch(apiUrl, { method: 'get', headers: new Headers({ Authorization: `Bearer ${getCookie('accessToken')}`, }), }) .then((response) => response.blob()) .then((myBlob) => { const objectURL = URL.createObjectURL(myBlob); setImageUrl(objectURL); });

};

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!