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

92
Visualizações
My example.downloadURL gives back an undefined

I am simply trying to test uploading images and I want to display the image, that is uploadoaded. My code looks like this:

function uploadFile(files){
    const storageRef = firebase.storage().ref(); //this references the firebase storage

    const horseRef = storageRef.child("horse.jpg");

    const file = files.item(0); //will return a list so lets take the first item

    const task = horseRef.put(file); //to upload the file we call the put file
    console.log(task);

    task.then(snapshot => { //returns a buncha data including a snapshot url
        const url = snapshot.downloadURL
        document.getElementById("upload").setAttribute("src", url)
    });

}

But the snapshot.downloadURL is giving back an undefined. Can you help me?

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

0

There isn't any downloadURL property on the snapshot which is an UploadTaskSnapshot. You need to use getDownloadURL() method on the storage reference to get the URL. Try refactoring the code as shown below:

task.then(async (snapshot) => { 
  const url = await snapshot.ref.getDownloadUrl()
  document.getElementById("upload").setAttribute("src", url)
});
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