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

289
Visualizações
React Native - Upload Array of Images to Firebase Storage

I am trying to upload an array of image URI's from application cache to firebase storage.

Once the images have been uploaded to firebase storage, the a callback to get the downloadURL for the file is called, and a document is created in firestore for the record. This record contains the first image. If multiple images have been taken, on the second photo, the firestore document is updated and new images are appended into image object (array).

Running this code has had 3 outcomes:

  1. 1 image uploaded
  2. all images uploaded
  3. no images loaded, application crashes

Any idea what I am doing incorrectly?

//Uploads Images
const uploadImages = async () => {
    for (const image of images) {
        const response = await fetch(image);
        const blob = await response.blob();
        const storageRef = firebase.storage().ref(REDACTED + ".jpg");
        const task = storageRef.put(blob);
        setLoading(true);
        task.on('state_changed', taskSnapshot => {
            console.log(`${taskSnapshot.bytesTransferred} transferred out of ${taskSnapshot.totalBytes}`);
        });
        await task.then(() => {
            const dlURL = storageRef.getDownloadURL().then((url) => {
                console.log("Download URL: ", url);
                updateFirestore(url);
            }).catch((error) => {
                console.log("Error getting download url: ", error)
            });
            setLoading(false);
            console.log("Image Successfully Uploaded");
        }).catch((error) => {
            console.error("Error Uploading Images: ", error);
            setLoading(false);
        });
    }
}
//Updates table in Firestore
const updateFirestore = (dlURL) => {
    console.log("PIC CODE: ", picCode);
    if (picCode === 0) {
        console.log("Creating Document...");
        //Create
        dbRef.add({
            ...
            images: [
                dlURL
            ]
        }).then((result) => {
            console.log(result);
            setDocID(result.id);
            //picCode++;
        }).catch((error) => {
            console.error(error)
        });
    } else {
        console.log("Updating Document...", docID);
        //Update
        dbRef.doc(docID).update({
            images: firebase.firestore.FieldValue.arrayUnion(dlURL)
        }).then((result) => {
            console.log(result);
            //picCode++;
        }).catch((error) => {
            console.error(error)
        });
    }
    picCode++;
};
Log Output:
Image:  file:///var/mobile/Containers/Data/Application/483FC505-968F-4850-87E3-8CC6DD824A53/Library/Caches/ExponentExperienceData/%2540arcade336%252Fempireportal/Camera/A68C3715-DD20-41C3-9711-E1C80E7B31A3.jpg
0 transferred out of 3777563
262144 transferred out of 3777563
786432 transferred out of 3777563
1835008 transferred out of 3777563

about 4 years ago · Juan Pablo Isaza
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