33

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 Answer 1

46

Firebase Storage tokens do not expire.

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

4
  • Does anyone know where I can find documentation that says this? I couldn't find any. The official docs for downloading images doesn't say anything, which I guess is good news. Sep 29, 2017 at 15:50
  • 2
    This doesn't seem right. I used the download URL from the firebase storage web API that is provided in the task returned from put(). (Documentation is here firebase.google.com/docs/storage/web/upload-files under Monitor Upload Progress). There's no mention of expiration, but now after a few months my download link resolves to this XML: <Error><Code>ExpiredToken</Code><Message>The provided token has expired.</Message><Details>Request has expired: 1511581939</Details></Error>
    – matth
    Dec 1, 2017 at 5:31
  • That most likely means your token was revoked. Dec 1, 2017 at 15:13
  • 17
    Okay now i am confused. @FrankvanPuffelen , can a downloadURL expire without me revoking the token from the console? matth's situation is very scary if it is true.
    – Nani
    Dec 24, 2017 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.