2
votes

I'm writing a firebase function where i need storage location. Right now i have download url:

https://firebasestorage.googleapis.com/v0/b/dxxxxxxxxx.com/o/videosvideo%3A67423?alt=media&token=acxxxxxxxxxxxxxxxxx

Is there a way to get Storage location like this:

gs://dexxxxxxxxxxxxxx.com/videosvideo:67423

from the given download url?

1
When you say "Firebase function", do you mean you're writing backend code with Cloud Functions for Firebase? Or are you writing client side code? Are you just trying to convert a https download URL to a gs URL?Doug Stevenson
Yes, i'm writing backend code with Cloud Functions for Firebase. And yes i want to convert a https download URL to a gs URL.Rishabh Chandel
Is there a way? @Doug StevensonRishabh Chandel
Is something wrong with refFromUrl? Seems like what you're looking for. See also stackoverflow.com/questions/42956250/…Kato

1 Answers

3
votes

The description for refFromURl says that it returns a Reference and accepts:

A URL in the form: 
1) a gs:// URL, for example gs://bucket/files/image.png 
2) a download URL taken from object metadata. 

Based on this, I'd expect the following to work fine:

const downloadUrl = "https://firestorage.googleapis...";
const gsUrl = firebase.storage().refFromUrl(downloadUrl).toString();