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?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
arvidurs
  • 2,853
  • 4
  • 25
  • 36
  • You can utilize the Google Cloud storage API using the gcs npm package to accomplish this - explanation @https://stackoverflow.com/questions/37749647/firebasestorage-how-to-delete-directory/49661881#49661881 – TheFastCat Apr 04 '18 at 23:24

1 Answers1

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49
  • 14
    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 up – arvidurs Jul 06 '16 at 07:34
  • 68
    It would be extremely useful to be able to delete entire folders and directories. Just letting you know that this is a requested feature – Keegan Jul 15 '16 at 20:47
  • 29
    Seems like a pretty big current Firebase limitation. – Rob Gorman Aug 11 '16 at 14:34
  • 20
    I need this feature in my life – RJH Sep 01 '16 at 16:14
  • 9
    I need this too! – CKP78 Oct 06 '16 at 10:00
  • 5
    Hi! Hope a soluton for this is coming soon – drv Oct 25 '16 at 10:50
  • 3
    Note that after deleting all the files inside the folder the folder gets deleted automatically. – Alaa M. Nov 04 '16 at 13:44
  • 4
    Hoping for solution to this as well. – Jeff Padgett Dec 10 '17 at 20:03
  • 8
    Wow, we at the end of 2017 and there is no solution. – Berkay Turancı Dec 18 '17 at 14:35
  • 3
    Very very pity ;( – Vlad Jul 12 '18 at 16:21
  • 2
    @BerkayTurancı end of 2018 is now – Vlad Jul 12 '18 at 16:22
  • 1
    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... – bibscy Aug 19 '18 at 19:02
  • 4
    we at the end of 2018 and there is no solution – Vlad Sep 12 '18 at 15:49
  • 4
    2019 but still no solution – uzaysan Jan 08 '19 at 16:35
  • 2
    Still no solution!? –  Jul 01 '19 at 00:26
  • As of Jul 2019, you can list a folder, and delete its contents recursively, see my answer here: https://stackoverflow.com/questions/37749647/firebasestorage-how-to-delete-directory/56844189#56844189 – Miki Jul 02 '19 at 17:28
  • Almost end of 2019 but still directory deletion option is pending – M.ArslanKhan Nov 26 '19 at 21:17
  • 2
    2020 and still no solution to delete a folder? – Catweazle Feb 17 '20 at 17:40
  • 1
    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 https://cloud.google.com/storage/docs/gsutil/addlhelp/HowSubdirectoriesWork for more). If GCS ever supports this, Cloud Storage for Firebase will, but I don't remember it being on their roadmap either. – Mike McDonald Mar 06 '20 at 21:00
  • 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. – Mike McDonald Mar 06 '20 at 21:01
  • 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. :( – Lukas Luke Stateczny Apr 07 '20 at 23:51
  • You can do this in 2020 `await firebase().storage().bucket().deleteFiles({ prefix: 'path/to/directory' })` – omeanwell Feb 05 '21 at 13:05
  • 2
    2022 and it still doen't work – Rafael Lima Jul 15 '22 at 22:21