Firebase Storage: Best Ways to sync files for offline use

2,876 views
Skip to first unread message

Thomas Wooldridge

unread,
Dec 5, 2016, 3:40:34 PM12/5/16
to Firebase Google Group
First of all, I'd just like to thank all of the Firebase gurus out there for their hard work - Firebase is awesome and is just amazing!

I'd like to get your thoughts on the best way to sync files in Firebase storage for offline use.

I am hoping that if I request an image from storage that it would grab the cloud version if it didn't exist locally, then use the local version on subsequent calls.  Is this correct?
It would also need to update locally if the file is changed.  Does it do that already?

Thanks for all your great work and help.

Untung Suryono

unread,
Dec 6, 2016, 12:25:55 AM12/6/16
to Firebase Google Group
You could use Glide and FirebaseImageLoader. Glide will cache the image and use that if it's storage reference remain the same.

Here's what you can do to update the local image when it is updated on server:
- check it's metadata to get the updatedTimeMillis
- whenever it's updated, save it to preference
- when loading the image, use Glide's .signature(new StringSignature(pref.getUpdatedTimeMillis()))

Glide will download the updated image immediately if the signature is changed. Otherwise, it will load the local image instead.

Mike Mcdonald

unread,
Dec 6, 2016, 2:37:38 AM12/6/16
to Firebase Google Group
This method is used by FirebaseUI Storage (Android, iOS), and you can see some more discussion here.

More generally, you'll want to use the cache-control header and some HTTP library that caches the file. If it changes locally, you'll have to invalidate the local cache and re-download the file--across phones, you might want to use a sync system like the Realtime Database to tell the other devices to invalidate their caches and re-download the file.

Thanks,
--Mike
Reply all
Reply to author
Forward
0 new messages