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

197
Visualizações
I'm trying to upload image but image is not adding to cloud firestore, its uploaded on firebase storage But not showing in React app

This is the code for uploading image on React app. Its showing on firebase storage but not added in to cloud firestore. and that's why I am not able to upload any image on React app manually. I've googled and searched so many times but cant fix this.

function  Imgupload({username}){

**strong text**    const [caption,setCaption]=useState('');
    const [image,setImage]=useState(null);
    //const [url,setUrl]= useState("");
    const [progress,setProgress]=useState(0);

    const handlechange = (e)=>{
       if(e.target.files[0]){
           setImage(e.target.files[0]);
       } 
    };

    const handleUpload = () =>{
      const uploadTask= storage.ref('images/$ {image.name}').put(image);
      
        uploadTask.on(
         "state_change",
         (snapshot) =>{
             //progress function..
         const progress=Math.round(
            (snapshot.bytesTransferred/snapshot.totalBytes) * 100
            );
            setProgress(progress);
         },
         (error) =>{            //error func..
            console.log(error);
             alert(error.message);
         },
         ()=>{ //complete func..
           storage
           .ref("images") 
           .child(image.name)
           .getDownloadURL()
           .then (url =>{
        //post img on db..
          db.collection("posts").add({
            timestamp:firebase.firestore.FieldValue.serverTimestamp(),
            caption  :caption,
            imgurl   :url,
            username :username   
        });
           setProgress(0);
            setCaption("");
            setImage(null);
           });
         }
      );
    }

This is the Error from console:

localhost/:1 Uncaught (in promise) FirebaseError: Firebase Storage: Object 'images/Screenshot (202).png' does not exist. (storage/object-not-found)
{
  "error": {
    "code": 404,
    "message": "Not Found."`enter code here`
  }
}

Can't fix this problem. please help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You have an extra space in the file name here:

const uploadTask= storage.ref('images/$ {image.name}').put(image);
                                    // 👆

You don't have that same space when you call getDownloadURL here:

storage
 .ref("images") 
 .child(image.name)
 .getDownloadURL()

So these two code fragments point to different files, which explains why the second fragment can't find the file you uploaded.


I recommend using a single variable to hold the reference, and use that in both fragments:

const imageRef = storage
 .ref("images") 
 .child(image.name);
const uploadTask= imageRef.put(image);

...

imageRef.getDownloadURL()...
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