Delete folder with contents from Firebase Storage [duplicate]
Asked Answered
K

1

20

I can easily delete a file within a child reference, but how would I delete the entire folder from Firebase Storage?

let postRef = FIRStorage.storage().reference().child("posts/folderName")
    postRef.deleteWithCompletion { (error) in
        print(error)
    }

Error file does not exists. Any ideas?

Keane answered 5/7, 2016 at 22:49 Comment(1)
You can utilize the Google Cloud storage API using the gcs npm package to accomplish this - explanation @#37750147Hephzipah
W
24

Long story short, we haven't implemented a recursive (or folder) delete. This topic is covered in another post: FirebaseStorage: How to Delete Directory

For now, we recommend either storing a list of files in another source (like the Realtime Database) or using the list API, and then deleting files as necessary.

You can also perform this type of delete in the Firebase Console (console.firebase.google.com).

In the future, we may offer this sort of functionality, but don't have it fully spec'ed out.

Wastrel answered 6/7, 2016 at 3:23 Comment(23)
Hm so now I should loop over all the files and deleted them one by one. Seems a bit odd okay. But thanks for the heads upKeane
It would be extremely useful to be able to delete entire folders and directories. Just letting you know that this is a requested featureMechling
Seems like a pretty big current Firebase limitation.Kaleidoscopic
I need this feature in my lifeTilton
I need this too!Camire
Hi! Hope a soluton for this is coming soonPainless
Note that after deleting all the files inside the folder the folder gets deleted automatically.Incapacitate
Hoping for solution to this as well.Rosefish
Wow, we at the end of 2017 and there is no solution.Kaycekaycee
Very very pity ;(Collogue
@BerkayTurancı end of 2018 is nowCollogue
I can't delete the folder in the firebase console. A pop up window is shown when I try to delete the folder, but it does not delete the file...Jejune
we at the end of 2018 and there is no solutionCollogue
2019 but still no solutionReinhardt
Still no solution!?Terbecki
As of Jul 2019, you can list a folder, and delete its contents recursively, see my answer here: #37750147Intrusion
Almost end of 2019 but still directory deletion option is pendingEclogite
2020 and still no solution to delete a folder?Subreption
I'm no longer working on Firebase or at Google, so I can't speak authoritatively at this point, but I did build the original product. The normal Google Cloud Storage product doesn't support "folder level" deletes because folders do not exist (every object lives in a flat namespace, / in names just happens to make gsutil and the object viewer treat things as "files and folders", see cloud.google.com/storage/docs/gsutil/addlhelp/… for more). If GCS ever supports this, Cloud Storage for Firebase will, but I don't remember it being on their roadmap either.Wastrel
Your solutions at this point are to implement client-side recursive delete, which is what the UI (Google Cloud and Firebase) as well as gsutil do.Wastrel
It's kinda pity. I love firebase products, but a simple user delete from the app makes this whole firebase storage a nightmare. I have to find users profile pic, images of items and delete them one by one instead of just deleting the folder that would hold all of those pictures. :(Unwitnessed
You can do this in 2020 await firebase().storage().bucket().deleteFiles({ prefix: 'path/to/directory' })Manifold
2022 and it still doen't workSwaziland

© 2022 - 2024 — McMap. All rights reserved.