I am trying to upload an array of images to firebase storage. I have written a function for single image upload and it works perfectly, but i cannot seem to wrap my head around how I can implement image array upload. Can someone kindly point me in the right direction. Below is my sample, and I have kept only the relevant part
uploadAsync = async uri => {
const user = Firebase.auth.currentUser.uid;
const path = `users/${user}/images/${Math.round(
Math.random() * 1000000000
)}.jpg`;
return new Promise(async (res, rej) => {
const response = await fetch(uri);
const file = await response.blob();
const upload = Firebase.storage().ref(path).put(file);
upload.on(
'state_changed',
snapshot => {},
err => {
rej(err);
},
async () => {
const url = await upload.snapshot.ref.getDownloadURL();
res(url);
}
);
});
};
updateImage = async ({ image }) => {
const user = Firebase.auth.currentUser.uid;
for (let i = 0; i < image.length; i++) {
const file = image[i].image;
const remoteUri = await this.uploadAsync(file);
const firestoreRef = firebase.firestore().collection('Images').doc(user);
firestoreRef.set({
image: [remoteUri]
});
}
}