2

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?

Rishabh Chandel
  • 725
  • 1
  • 11
  • 28
  • 2
    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 Jun 13 '17 at 23:23
  • 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 Jun 14 '17 at 08:15
  • Is there a way? @Doug Stevenson – Rishabh Chandel Jun 14 '17 at 15:15
  • Is something wrong with [refFromUrl](https://firebase.google.com/docs/reference/js/firebase.storage.Storage#refFromURL)? Seems like what you're looking for. See also https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase – Kato Jun 14 '17 at 19:19

1 Answers1

3

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();
Kato
  • 40,352
  • 6
  • 119
  • 149
  • Whenever i use firebase.storage() i get error firebase.storage is not a function. I know i have to use google cloud storage, but for that too i get gcs.ref is not a function. Anyway i needed bucket and filepath only from gs url which i manipulated from http url itself. Thanks though for your feedback. – Rishabh Chandel Jun 14 '17 at 19:40
  • Hello Kato, would you know the answer to this ? https://stackoverflow.com/questions/44758262/how-to-implement-steam-auth-with-firebase – TheProgrammer Jun 27 '17 at 12:02