Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda