Skip to content
Advertisement

How to remove images from Firebase Storage?

I’m trying to adapt a React Native project to the new Firebase methods. In it I upload images to Storage and they are added to the App interface. I can also remove these images from the interface as shown in the following code:

JavaScript

The problem is that in this way, they are only removed from my App, while the images are still stored in Firebase. My idea is that when I remove the images from the frontend, they will also be removed from the Firebase Storage.

I have read Firebase documentation, and this would be possible with the deleteObject function

JavaScript

I did some test, and I can’t get it to work. I don’t know exactly how I should add the Firebase instructions shown here.

How should I implement this function in my code to remove images from Storage?

Thank you

JavaScript

Advertisement

Answer

I finally figured out where to implement the deleteObject function in my file to make it all work. You can delete the images from the Application and Firebase Storage at the same time. I found a React expert who helped me with this.

As the Firebase documentation says:

To delete a file, first create a reference to that file.

( const imageRef = ref(storage, img ))

Firebase explains it like this:

JavaScript

Then call the delete() method, (in my case: deleteObject(imageRef) ), for that reference, which will return either a Promise that resolves, or an error if the Promise is rejected.

JavaScript

I just hope this can help other users who are in my situation learning Firebase

I show. the complete file so that they do not have the doubts that I had, which was the correct place where I should place the Firebase methods

JavaScript

Thanks to @FrankvanPuffelen and @BhavyaKoshiya who tried to help.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement