Reputation: 13
How to delete image from Firebase storage by url? When I remove item(category) from collection, image remains in storage.
Interface category:
export interface ICategory {
readonly id : string
name : string
image : string
}
Function for remove
export const removeCategoryFB = (id: string, setCategories: any) => {
firestore()
.collection("categories")
.doc(id)
.delete()
.then(() => {
getCategoriesFB(setCategories);
})
.catch((err) => {
alert(err);
});
};
Upvotes: 0
Views: 1036
Reputation: 13
I resolve this problem with
refFromURL(URL)
Example code
firestore()
.collection('categories')
.doc(id)
.get()
.then((snapshot) => {
storage()
.refFromURL(snapshot.data().image.url)
.delete()
})
Upvotes: 1
Reputation: 897
You need to get storage reference then you will give file storage path to delete the file.
deleteChatFiles(filePath) {
const spaceRef = firebase
.storage()
.ref()
.child(filePath);
spaceRef.delete();
}
this.deleteFile('files/1579283129986-vMglgpHwT6c06RSmAiuYP6Hk2sz1.png');
Upvotes: 0