How to use WriteBatch with Firebase storage?

Tags: , , ,

I’m using Firebase cloud database and firebase storage. I’m using the following code in order to remove two documents using WriteBatch:

WriteBatch batch = fireDB.batch();
batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {

    public void onComplete(@NonNull Task<Void> task) {
        // code

I want also to remove the image from the storage using WriteBatch, meaning, if one of them fails, they all fail to remove. I have a variable called imageURL which contains the URL of the image in the firebase storage. I tried:


But it does not work because:

‘delete(’ in ‘’ cannot be applied to ‘(’

Is it possible to do?


There is no way to run a single operation across multiple Firebase products.

The best you can do is:

  • Perform the deletes in the order that leads to the least problems for your use-case. Typically this means deleting the images last, as having an orphaned image is less disruptive for an app than having a dangling reference to a non-existing image.
  • Write robust code for the reading, that can deal with both orphaned images, and dangling references.
  • Perform periodic cleanup, typically in a Cloud Function, getting rid of both orphaned files and dangling references.

Source: stackoverflow