Firebase - download images when the Internet is off

Firebase has an excellent ability to use its database and send data to its dB, even if you are offline, and then when the connection is re-inserted, it automatically sends data to db.

is it also possible to do this with Firebase storage, for example, send images even if the Internet is turned off, and then when the Internet is turned on again, will it automatically send image files?

If so, how can I do this? If not with Firebase, any other option?

+5
source share
1 answer

Yes. The Firebase Storage client supports resuming downloads. See the Firebase Storage Documentation for downloads ( iOS , Web , Android ).

From there for Android:

uploadTask = mStorageRef.putFile(localFile); sessionUri = uploadTask.getUploadSessionUri(); //save the sessionUri to persistent storage in case the process dies. 

And then resume:

 //resume the upload task from where it left off when the process died. //to do this, pass the sessionUri as the last parameter uploadTask = mStorageRef.putFile(localFile, new StorageMetadata.Builder().build(), sessionUri); 

Update (20160809)

One way to handle sessionUri:

  • when you create uploadTask , get sessionUri and save it in the SharedPreferences application.
  • when uploadTask completes, remove sessionUri from the SharedPreferences application.
  • when the application restarts, check if there is a sessionUri in the SharedPreferences . If yes: resume downloading.
+5
source

All Articles