How to synchronize files from firebase storage to app's assets folder?

There is nothing specific built into Cloud Storage's Firebase SDK for this, so you'll have to build it in your own application code.


Using only the Cloud Storage for Firebase API

If you're just using Cloud Storage, you'll have to:

  1. List all files that you're interested in from Storage.
  2. Loop over the files.
  3. Get the metadata for each file and check then the files was last updated
  4. Compare that to when you wrote the local file.
  5. Download the file if it is new or modified.

This approach will work, but it requires quite some calls to the Storage API, because there's no specific API to give you files that were modified since a specific date/time.


Storing metadata in a cloud database

You could also consider storing the metadata in a cloud database, like Firebase's Realtime Database or Cloud Firestore, and then use the query capabilities of that database to retrieve only files that were modified since your device last synchronized.

The recipe then becomes:

  1. Determine when we last synchronized, which is a value you'll want to store in local storage/shared preferences.
  2. Execute a query to the database to determine which files were added/modified since then.
  3. Loop over the query results and...
  4. Download each file that was modified.

In here, only step 2 and 4 make calls to the external APIs, so it is likely to be faster and cheaper to execute (but more work for you to write initially).