I have the following script
let link = ""
let baseUrl = "Test-Dataset/"
let imageRef = "2.jpg"
storage.ref(baseUrl + imageRef).getDownloadURL().then(
function(url) {
link = url
console.log(url)
}).catch(function(error) {
});
console.log(link)
My goal is to update the link
variable with the value of the image's URL after I use the getDownloadURL()
to return a promise and wait for it to be resolved. The console.log
function within the .this() is outputting exactly what I need - the link to the image in my firebase storage. However, the console.log
outside of the function is returning the initial value of link
before the call to my firebase storage was made, which is just ""
. Why does this happen? Is my solution to make something like the asynchronous function outlined in https://stackoverflow.com/a/53578626/8849802?
Details: I'm using vue and the npm library firebase