Reputation: 23
I am creating a Flutter app that uses Firebase storage. I have the structure of a collection with the user data in Firestore and a folder on the Firebase storage with named after the uid of the current user. However if the user want to delete the account all the images have to be removed. Is there a way to remove an entire directory in Firebase storage through Flutter?
The files are uploaded as such:
// Upload img
firebase_storage.Reference storageRef = firebase_storage
.FirebaseStorage.instance
.ref()
.child('images/users/' + uid + '/mealImages/' + fileName);
firebase_storage.UploadTask uploadTask = storageRef.putFile(imageFile);
// Remove img where uid=aaa and fileName=bbb.jpg
await firebase_storage.FirebaseStorage.instance
.ref()
.child(
'images/users/aaa/mealImages/bbb.jpg')
.delete();
Upvotes: 2
Views: 770
Reputation: 598765
Folders in Storage are automatically created when you add the first file to them, and automatically deleted when you delete the last file from them.
So the only way to get rid of the entire folder of files for your user, is to delete each individual file from it..
Upvotes: 1