This is the code snippet where I want to get the URL of all uploaded images in promise.all
but when I am invoking the uploadFile
function, it returns an empty array. Can anyone please help me on this issue.
export default function uploadFile(fileInfo) {
const promises = [];
fileInfo.forEach((item) => {
const uploadTask = projectStorage
.ref()
.child(`${item.path}/${item.imageName}`)
.put(item.file);
// promises.push({ task: uploadTask });
uploadTask.on(
"state_changed",
(snapshot) => {
promises.push(snapshot);
const progress =
(snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(`Progress: ${progress}%`);
},
(error) => console.log(error.code),
async() => {
promises.push(await uploadTask.snapshot.ref.getDownloadURL());
}
);
});
return Promise.all(promises);
}