Pranav
Pranav

Reputation: 441

How to delete a whole file from firebase storage - flutter

This is how my DB looks like: enter image description here

and I wanna delete everything on that file.

This is what I've tried so far:

FirebaseStorage.instance.ref().child("User ($uid)/ads").delete();
FirebaseStorage.instance.ref().child("User ($uid)/ProfilePic").delete();

the second line deletes the ProfilePic, but the first line returns an error.
I'm new to firebase and flutter so bear with me.

Upvotes: 1

Views: 324

Answers (1)

Piyush Maurya
Piyush Maurya

Reputation: 2015

There is no firebase API to delete all the files with a certain prefix i.e. files you see in the console within a certain folder.

One way to achieve this is by using listAll() method to fetch all the files with certain prefix and delete them individually later.

Flutter firebase storage listAll() method is currently available in dev version of package, in version 5.0.0-dev.1, which you can use as shown below:

firebase_storage.ListResult result =
      await firebase_storage.FirebaseStorage.instance.ref().listAll();

After using listAll(), you'll get all the files and then you can delete them individually.

Additionally, you can delete files on your backend server also.

Upvotes: 1

Related Questions