Reputation: 1157
I am trying to retrieve the downloadURL from an image I uploaded to Firebase. No problem getting the correct URL inside the promise.
I don't understand why downloadURL is still undefined after I set it equal to the url returned in the .then statement.
let downloadURL;
firebase
.storage()
.ref()
.child('project_images/' + imageName)
.getDownloadURL()
.then(url => {
downloadURL = url;
console.log(downloadURL); //logs the correct downloadURL needed
})
.catch(error => {});
console.log(downloadURL); //still undefined
I feel like I am missing something stupid but for the life of me I can't see what it is. Any help appreciated. Thank you!
Upvotes: 0
Views: 413
Reputation: 491
Does it log the undefined
before the one inside the promise?
It's likely just not completing the promise before you try and log outside the function calls.
Upvotes: 1