Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda