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

154
Vistas
Unable to convert url image response to buffer using nodejs

I am working on downloading image from url using nodejs. But I am unable to convert response to buffer. Image I receive from response is in gibberish form.. Following is my code:

app.get('/test', async (req, res) => {
  const data = await fetch("https://api.image/test.jpg");
  res.send(Buffer.from(data));
});

Response of fetch API is: enter image description here

Error after downloading image is:

Image is

I also tried following buffer encoding but I still getting above error after downloading image:

 Buffer.from(data,'base64');
 Buffer.from(data,'ascii');
 Buffer.from(data,'base64url');
 Buffer.from(data,'binary');
 Buffer.from(data,'hex');
 Buffer.from(data,'latin1');
 Buffer.from(data,'ucs-2');
 Buffer.from(data,'ucs2');
 Buffer.from(data,'utf-8');
 Buffer.from(data,'utf16le');
 Buffer.from(data,'utf8');
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think this should be like:

app.get('/test', async (req, res) => {
  const data = await fetch("https://api.image/test.jpg");
  res.send(Buffer.from(await data.arrayBuffer()));
});
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