Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Firebase delete images from url

I need to delete images from firebase storage (react.js), but when I try to recover the url the console gives me: FirebaseError: Firebase Storage: Object 'images/[object Object]' does not exist. (storage/object-not-found) { "error": { "code": 404, "message": "Not Found." } }

This is the code:

const deleteFromFirebase = (url) => {
    
        let imageRef = storage.ref(`/images/${url}`);
            
            imageRef.delete().then(() => {
            console.log("Deleted")
        }).catch(err => console.log(err))
      };

I need to insert the index?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The imageUrl variable is not a URL

You can prove it by inserting the following console.log at the top of your function:

const deleteFromFirebase = (url) => {

  console.log(JSON.stringify(url, null, 2);  

And it shouldn't actually be a URL

A URL is a thing like https://stackoverflow.com/questions/70558620/firebase-delete-images-from-url. You wouldn't want to be storing your image at the following location, would you?

/images/https://stackoverflow.com/questions/70558620/firebase-delete-images-from-url

Therefore I suggest that in your "deleteFromFirebase" function you do not call it a URL, but rather a "pathWithinImagesFolder" or something, that will reduce scope for confusion.

Next step is to find out what the firebase storage function is returning

const imageUrl = await storage.ref('images').child(uploadTask.metadata.name).getDownloadURL();

console.log("Original value is ",imageUrl)
   

I suspect it is returning an extra-long URL, perhaps with extra things added at the end to give permissions to download, etc.

My suggestion

Revise all your terminology. There are two separate things.

  • pathWithinImages, e.g. house.png;
  • downloadUrl, e.g. https://google.something.blahblah/bucketName/blah blah?downloadKey=239850598745

So when you are uploading, make this clear:

const pathWithinImages = uploadTask.metadata.name 
const downloadUrl = await storage.ref('images').child(pathWithinImages).getDownloadURL();

Store both the pathWithinImages and the downloadUrl.

When you come to delete the image, use the pathWithinImages.

const deleteFromFirebase = (pathWithinImages) => {

    storage.ref(`/images/${pathWithinImages}`)
      .delete()
      .then(() => {
        console.log("Deleted")
      }).catch(err => console.log(err))
  };
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!