Implementing file deletion
Up until now, we have managed to upload and download our files from theStorage
bucket, but sometimes we really want to delete the files we uploaded previously. This is doable using the Firebase Storage bucket APIs we used in the previous two sections.
How to do it...
- As we discussed in the previous chapters before we do anything we need to grab ourselves a reference for the wanted file, so let's do that! The code for creating a reference is given as follows:
//Getting the Root Folder Reference. var rootRef = firebase.storage().ref(); var imageRef = rootRef.child('images/<image-name>. <image-ext>');
- Now let's use a special method or function that will help us to delete this particular file. We're talking about the
delete()
method, which we will see how to implement using the following code:
imageRef.delete() .then(() => { //We successfully deleted the file. }) .catch(err => { //Report/Showcase...