Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda