I am basically new to Angularfire2, I am trying to delete a folder from Firebase Storage when the user presses the delete button. Unfortunately, such information is not in the Angularfire2 documentation.
I have basically tried to use the code below:
constructor(private afs: AngularFirestore, private storage: AngularFireStorage) {
this.clientsCollection = this.afs.collection('clients', ref => ref.orderBy('uid', 'asc'));;
}
deleteClient(client, callback){
this.storage.ref(client.uid).delete();
}
Unfortunately, it throws the following error
FirebaseStorageError {code_: "storage/object-not-found", message_: "Firebase Storage: Object '3CqyNHrIwQ3sRlj83JKM' does not exist.", serverResponse_: "{↵ "error": {↵ "code": 404,↵ "message": "Not Found. Could not delete object"↵ }↵}", name_: "FirebaseError"}
I have stored each client's documents in a folder which has the name similar to the client's uid. Which is really just an ID generated by Firebase. I get the above error when I try to delete that folder. Please help, how do I go about this?
I think a better way would be to delete a file via its download URL. To do that, you can simply call storage.refFromURL(url).delete()
on the instance of the injected AngularFireStorage
dependency.
...
constructor(private storage: AngularFireStorage) { }
...
delete(downloadUrl) {
return this.storage.storage.refFromURL(downloadUrl).delete();
}
...
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