I am trying to delete all the images from a folder in firebase, or delete the folder itself and all the images that way.
I have looked at the solution from MIKI: FirebaseStorage: How to Delete Directory
I cant get it to work. The images are placed in the bookPictures folder under another folder with the ID of the book.
Folder structure looks like this: Folderstructure in firebase
Here is my code:
this.deleteFolderContents(`/bookPictures/${id}`)
deleteFolderContents = (path) => {
const ref = firebase.storage().ref(path)
ref.listAll().then(dir => {
dir.items.forEach(fileRef => {
this.deleteFile(ref.fullPath, fileRef.name);
});
dir.prefixes.forEach(folderRef => {
this.deleteFolderContents(folderRef.fullPath);
})
})
.catch(error => {
console.log(error.message)
});
}
Update: In the solution from MIKI he uses the deleteFile. I thought it was a firebase function. I logged the error: _this.delete is not a function. (In '_this.delete(ref.fullPath, fileRef.name)', '_this.delete' is undefined)
How do i delete images ?