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?
After uploading files to Cloud Storage, you can also delete them. Note: By default, a Cloud Storage bucket requires Firebase Authentication to perform any action on the bucket's data or files. You can change your Firebase Security Rules for Cloud Storage to allow unauthenticated access.
To delete a file, first create a reference to that file. Then call the delete() method on that reference, which returns a Promise that resolves, or an error if the Promise rejects.
There is no API for bulk or batch deleting files in Cloud Storage. You will have to delete each one individually as described in the documentation.
To delete a file from the firebase storage we need a reference to store the file in storage. As we only have the file URL we need to create a reference object of the file in firebase storage and then delete that file. Get the reference to the storage using refFromUrl method from firebase. storage.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With