Deleting a folder from Firebase Cloud Storage in Flutter


I have a Flutter mobile app in which I am trying to delete a folder (and its contents) from Firebase Cloud Storage. My method is as follows:

deleteFromFirebaseStorage() async {
     return await FirebaseStorage.instance.ref().child('Parent folder/Child folder').delete();

I expect Child folder and its contents to be deleted, but this exception is thrown:

Unhandled Exception: PlatformException(Error -13010, FIRStorageErrorDomain, Object Parent folder/Child folder does not exist.)

However I can clearly see that folder exists in Cloud Storage. How do I delete this folder?


Cloud Storage doesn’t actually have any folders. There are just paths that look like folders, to help you think about how your structure your data. Each object can just have a common prefix that describes its "virtual location" in the bucket.

There’s no operations exposed by the Firebase SDKs that make it easy to delete all objects in one of these common prefixes. Your only real option is to list all files in a common prefix, iterate the results, and delete each object individually.

Unfortunately, the list files API has not made it to flutter yet, as discussed here. So you are kind of out of luck as far as an easy solution is concerned. See also: FirebaseStorage: How to Delete Directory

Your primary viable options are:

Answered By – Doug Stevenson

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *