Having an issue with my firebase storage upload - I am uploading three photos, but when I try to retrieve the firebase URL for each image using getDownloadURL, it only returns two objects instead of three.
//const uploadedFilesURL = [];
uploadToStorage.map((image) => {
const storageRef = ref(storage, `images/${image.name + v4()}`);
uploadBytes(storageRef, image).then((snapshot) => {
getDownloadURL(snapshot.ref).then((url) => {
//console.log(image);
//console.log(url);
uploadedFilesURL.push({file: image, url})
})
});
});
console.log(uploadedFilesURL);
Oddly enough, when I log the image and URL individually, I get the three objects I need (although I don't want to log the image itself).
const uploadedFilesURL = [];
uploadToStorage.map((image) => {
const storageRef = ref(storage, `images/${image.name + v4()}`);
uploadBytes(storageRef, image).then((snapshot) => {
getDownloadURL(snapshot.ref).then((url) => {
console.log(image);
console.log(url);
uploadedFilesURL.push({file: image, url})
})
});
});
console.log(uploadedFilesURL);
My goal is to extract the firebase URL path so that I can store it in a separate database as a reference, hence why I am creating the uploadedFilesURL object.
Thank you!