Home > Blockchain >  Delete from list of files in firebase using refFromURL
Delete from list of files in firebase using refFromURL

Time:03-29

I've searched all over the internet but I'm unable to delete a file from storage using refFromURL in firebase v9. I tried using firebase.storage().refFromURL(url) to fetch the path but its states that firebase.storage is not a function. Is their any work around in firebase v9?

  const deleteGalleryImage = (attachment, index) => {
    // console.log(getRefFromURL(attachment));
    let pictureRef =  firebase.storage().refFromURL(attachment);
    pictureRef
      .delete()
      .then(() => {
        setAttachments(attachments.filter((image) => image !== attachment));
      })
      .catch((error) => console.log(error));
}
 

CodePudding user response:

If you're using v9 then you can't use the namespace refFromUrl method anymore. The equivalent operation is now built into the top-level ref function.

So to get a ref from a URL, you'd do something like:

import { getStorage, ref } from "firebase/storage";

const storage = getStorage();

const storageRef = ref(storage, "your URL here");
  • Related