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

120
Visualizações
How to view an uploaded image in react in the browser

I have a react frontend, and I want to view the image on the browser when I upload the image. Below is my uploading function

onDrop = async (files) => {

    const FILES = {
        "uploaded_image": [{
            name: files[0].name, <- Name prints on screen succesfully
            image: files[0].file, <- It is just empty
        }]
    }

    this.setState({
          ...some states
    })
   ..some calls
}

And below is the render

<div>
     <Image
     src={this.state.files[0].image}
     />
 </div>

The image shows if I hardcode the field directly,

image: require(`static_media/car.png`).default

But I would like to show without hardcoding the path of the uploaded file, how can I modify the image field in the onDrop to do that?

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

0

you need to use URL.createObjectURL(files[0])

 const FILES = {
    "uploaded_image": [{
        name: files[0].name, <- Name prints on screen succesfully
        image: URL.createObjectURL(files[0]), <- It is just empty
    }]
}
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