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

235
Vistas
How to use a binary string to display an image in an image tag?

I upload an image and send it to the back-end with this code:

const formData = new FormData();
formData.append('file', event.target.files[0]);

Then I am getting the payload of this image from the back-end which has a type of binary string. I want to display the image and I already tried this solutions:

  1. Convert to a Blob and use it like this
const blob = new Blob([payload]);
<img src="data:image/png;base64,'+ blob" />
  1. Use FileReader and readAsDataURL
var reader1 = new FileReader();
reader1.readAsDataURL(new Blob([payload]));
reader1.onload = function () {
    let paar: any = document.getElementById('imagePreview');
    paar.src = reader.result;
};
  1. createObjectURL Blob
const blob = new Blob([payload]);
const url = URL.createObjectURL(blob);
const img: any = document.getElementById('imagePreview');
img.src = url;
img.onload = (e) => URL.revokeObjectURL(url);

Here the url looks like this: blob:http://localhost:3000/92540eea-6f01-46db-86d0-14491a8b6abf and it doesn't work, because it should look something like this: "data://base64".

How can I display this image ?

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