user11877466
user11877466

Reputation:

Put URL to Firebase Storage file into variable

I'm trying to put the URL of my image into a variable so I can log the URL from the image to the console. I don't know why, but every time I try to do that it just doesn't log anything (and also gives no error). This is the way I'm trying it now:

}, function() {
  // The file is done uploading to Firebase Storage
  let url = uploadTask.snapshot.downloadURL;
  console.log(url)
}

I really don't know what I'm doing wrong and I know this is probably not the hardest thing to figure out, but I really can't find it. Can someone help me, please?

Upvotes: 0

Views: 56

Answers (1)

palaѕн
palaѕн

Reputation: 73936

You can access downloadURL like:

task.on('state_changed', function(snapshot){
  //....
}, function(error) {
  // Handle unsuccessful uploads
}, function() {
  // Handle successful uploads on complete
  task.snapshot.ref.getDownloadURL().then(function(downloadURL) {
    console.log('File available at', downloadURL);
  });
});

Upvotes: 1

Related Questions