I am building a web app with flutter, and I want to be able to clear the complete Firebase Storage with a buttonpress. Is there any way to do this? Thanks for the help.
Asked
Active
Viewed 689 times
0
-
1You can simply call `delete()` on a document or collection. https://firebase.flutter.dev/docs/firestore/usage/#removing-data – Alex Meuer Aug 28 '20 at 08:45
-
But doesn't that only work for firebase? I want to use it in firebase storage. – Bennett567 Aug 28 '20 at 08:56
-
1Ah, I see, my bad. I misunderstood your question. – Alex Meuer Aug 28 '20 at 09:13
-
OKay, thanks anyway! – Bennett567 Aug 28 '20 at 09:14
-
1From looking around, it doesn't seem to be possible to delete an entire directory: https://stackoverflow.com/a/38215897/4571656 There's no mention of it either in the documentation, just single file deletion. You may have to get a list of files and delete them one by one. – Alex Meuer Aug 28 '20 at 09:16
1 Answers
1
The Cloud Storage for Firebase SDK doesn't provide any options to remove all objects from a storage bucket. If you want to do this in your app, you will need to find each object using a StorageReference object, then call delete() on each one individually.
Since the Flutter SDK currently lacks a way to list files in a bucket, you might be helped by storing a reference to each file in a database, and querying the database to find each one to delete.
If you just want to manually clear the bucket during testing, you might find it easier to simply do that in the Firebase console.

Doug Stevenson
- 297,357
- 32
- 422
- 441