22
votes

I have a question regarding the "token" in the url(&token=) when using getDownloadUrl of FirebaseStorage.

https://firebasestorage.googleapis.com/v0/b/someapplication.appspot.com/o/images%2Fsample.png?alt=media&token=123456

From docs, it says that it returns a "long lived" download url https://firebase.google.com/docs/reference/js/firebase.storage.Reference#getDownloadURL

Problem is, im saving the downloadUrl in FirebaseDatabase like

-chatroom
  - c1
    - m1
      -message: "Sent a photo"
      -photoUrl: downloadUrl here

From what i understand it is not a lifetime token so at some point in time the token will not be valid. So when I display this url in an ImageView for example, it will not load the image.

Picasso.with(context)
  .load(downloadUrl)
  .into(imageView)

I do understand I can use something like this in firebase to generate a new one.

StorageReference sr = getReferenceFromUrl(downloadUrl)
//pseudo-code
sr.getDownloadUrl().addOnSuccessListener((Uri newUri) => {
  Picasso.with(context)
  .load(newUri)
  .into(imageView)
});

BUT! this process has an overhead of always getting a new download url in the process.

So again, how long will the token lived? Also if it is not a lifetime token, how should we store the download url properly?

1

1 Answers

30
votes

Firebase Storage tokens do not expire.

They may be revoked from the Firebase Console, which would invalidate URLs based on them.