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

386
Visualizações
How can I turn the data that is a image came from API to url to use in img tag in react Js

I have uploaded an image. Now, I have a download API that gives me this image as a data. The response looks like this:

enter image description here enter image description here

the header of the response is like this:

enter image description here

Now the problem is that I want to show this image on the web page using img tag or anything else possible in react js. Passing the content to src attr shows nothing. Does anyone have any ideas? Is there any possible way?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should be able to use the FileReader to convert the response to base64 format which can be used in the src attribute:

// 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 Relatório

0

This also worked for me other than the answer above:

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 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