I'm trying to take an object, upload a file in the object, get the downloaded url and add it to the the object, the problem is whenever I try to push the new data to an array, I always end up missing one of the items and I can't tell why this is happening.
My code:
const transformedData = async () => { const urlList = []; for await (let dog of data.dogs) { // console.log(dog); if (dog.file.length === 0 || dog.file === undefined) { urlList.push({ ...dog, akcPapersUrl: "" }); } else { const uploadTask = await storageRef .child(`dog/${dog.akcNumber}/${dog.file[0].name}`) .put(dog.file[0]); uploadTask.ref.getDownloadURL().then((res) => { urlList.push({ ...dog, akcPapersUrl: res }); }); } } console.log(urlList); return urlList; }; await transformedData() .then((res) => { data = { ...data, transformed: res }; return data; }) .then((res) => { console.log(res); sendRegistration(res); });
https://stackoverflow.com/questions/65546273/pushing-to-list-results-in-one-item-always-being-left-out January 03, 2021 at 11:03AM
没有评论:
发表评论