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

232
Visualizações
Is there a way that I can generate a URL for an uploaded image?

I had been working on a component wherein when we upload an image from the desktop, It initially created an object URL using the URL.createObjectURL(). But, I recently read somewhere that createObjectURL is deprecated for the MediaStream. Also, I was getting this error:

"Failed to execute 'createObjectURL' on 'URL': Overload resolution failed."

I also got to know that we could set the srcObject to the MediaStream and that would work. But, for image upload, it was not working. Is there any way wherein I can create the temporary URL and set the img tag's src to that so that I am able to preview it on the web page? Any help is appreciated, Thanks!

Here is the code that I was previously using

const el = profilePicture.current;
const myMemoObj = URL.createObjectURL(event.target.files[0]);
el.src = URL.createObjectURL(event.target.files[0]);
URL.revokeObjectURL(myMemoObj);

I also tried setting the el.srcObject to event.target.files[0] but it didn't work out.

Edit: profilePicture is a ref attached to an img tag in the same component

profilePicture = useRef(null);
.
.
.
<img ref={profilePicture} alt="Profile Picture"/>
about 4 years ago · Juan Pablo Isaza
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