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?
The Firebase Storage token does not expire (see Stack Overflow). Therefore, without any other modifications, our downloadUrl also never expires and remains available.
A Firebase download URL is a long-lived, publicly accessible URL that is used to access a file from Cloud Storage. The download URL contains a download token which acts as a security measure to restrict access only to those who possess the token.
CORS Configuration To download data directly in the browser, you must configure your Cloud Storage bucket for cross-origin access (CORS). This can be done with the gsutil command line tool, which you can install from here. Run gsutil cors set cors. json gs://<your-cloud-storage-bucket> to deploy these restrictions.
Firebase Storage tokens do not expire.
They may be revoked from the Firebase Console, which would invalidate URLs based on them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With