Is there a way to iterate through all the files in a directory and
deleting them one by one?
Yes, you can use the listAll()
method, as follows:
const storageRef = firebase.storage().ref('temp');
storageRef.listAll().then((listResults) => {
const promises = listResults.items.map((item) => {
return item.delete();
});
Promise.all(promises);
});
Note that:
- This method is only available for Firebase Rules Version 2 (add
rules_version = '2';
at the top of the Security Rules).
- This is a helper method for calling
list()
repeatedly until there are no more results. The default pagination size is 1000.