Skip to content Skip to sidebar Skip to footer

How Do I Execute Multiple Firebase Uploads And Wait For The Collective Results

I am playing around with Firebase Storage baked into an photo collection app that takes a collection of photos and uploads them to a firebase storage backend. I want to upload mult

Solution 1:

The Play services Task API actually powers much of the Firebase client side asynchronous APIs, such as Firebase Storage file uploads. That UploadTask you have is a subclass of the standard Task that accepts success and failure listeners, as you're doing it now.

If you're dealing with multiple concurrent uploads and wish to know when all of them are complete, you can use the Tasks utility class which has a whenAll() method that accepts multiple Task objects. That method will return a new Task where you can register additional success and failure listeners. The success listener will be called as soon as all the Tasks are complete, and the failure listener will be called if and when any of the tasks fail.

You can register listeners both on the individual tasks, and also on the composite task returned from Tasks.whenAll().

(Also, stay tuned of an upcoming blog series about the use of the Task API with various Firebase features.)

Post a Comment for "How Do I Execute Multiple Firebase Uploads And Wait For The Collective Results"