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

209
Vistas
firebase.storage().ref().getDownloadURL() won't run

I am trying to upload an image to Firebase Storage and save the downloadURL in Firestore, but when my code is running, .getDownloadURL() won't run. The image uploads, but after that, nothing happens. My code is below. I've tried with several images.

const task = firebase.storage().ref('/hendingar/' + img.name).put(img)

task.then((snapshot) => {
  console.log('Img ')
  snapshot.ref.getDownloadURL((url) => {
    console.log('Url')
    firebase.firestore().collection('hendingar').add({
      title: title,
      description: description,
      start: start,
      end: end,
      place: infoPlace,
      prices: temp_arr,
      img: url,
    }).then(() => {
      console.log('Success')
    }).catch((error) => {
      console.error(error)
    })
  })
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're not getting any results or logs after console.log('Img ') because you're not chaining the promise properly. You must call the getDownloadURL() before chaining .then(). See code below:

const task = firebase.storage().ref('/hendingar/' + img.name).put(img)

// Uploads the file to Firebase Storage.
task.then((snapshot) => {
  console.log('Img')
  // You can also put the creation of Firestore Document here.
  // (If you want it to create the document before getting the download URL.)
  
 // Calls the `getDownloadURL()` method.
 snapshot.ref.getDownloadURL()
  .then((url) => {
    // Returns the Download URL from Firebase Storage.
    console.log('Url')
    console.log(url)
    
    // You can put this either here or before getting download URL.
    firebase.firestore().collection('hendingar').add({
      title: title,
      description: description,
      start: start,
      end: end,
      place: infoPlace,
      prices: temp_arr,
      img: url,
    }).then(() => {
      console.log('Success')
    }).catch((error) => {
      console.error(error)
    })
  })
})
.catch((error) => {
  // Logs error if there's an error uploading of file.
  console.log(error)
})

I leave some comments on the code above for better understanding. For more information, you may checkout this documentation.

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