Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda