前提
Vue2系でアップロードの処理を開発しているのですが、async.awaitを使用するためにForOfで処理するように記述しています。
しかし、並列処理にしたい観点からForOfからPromise.allに移行しようと考えております。
実現したいこと
ForOfで行っている処理をPromise.allに移行して同じ動作がするようにしたいです。
発生している問題・エラーメッセージ
Promise.allで書き換えてみたのですが、上手くアップロード処理が行われず(主にUpdate処理が)、書き方が間違っている気がしてならないです。 エラー等は吐いていません。
該当のソースコード
JavaScript
1async uploadAlbum() { 2 //forEachはasync・await出来ないからforOfで 3 for (const [index, file] of Object.entries(this.imageFiles)) { 4 if (!file) { 5 return; 6 } 7 const fileType = file.type.replace("image/", ""); 8 const currentUser = getAuth().currentUser; 9 const relativePath = `user/${currentUser.uid}/${index}.${fileType}`; 10 this.imageFiles[index] = await this.mixinUploader__upload( 11 file, 12 relativePath 13 ); 14 } 15 // forOfで書いた場合 16 // await Promise.all( 17 // Object.values(this.imageFiles).map(async (file, index) => { 18 // if (!file) { 19 // return; 20 // } 21 // console.error(file); 22 // const count = index + 1; 23 // const fileType = file.type.replace("image/", ""); 24 // const currentUser = getAuth().currentUser; 25 // const relativePath = `user/${currentUser.uid}/${count}.${fileType}`; 26 // this.imageFiles[count] = 27 // await this.mixinUploader__upload(file, relativePath); 28 // }) 29 // ); 30 },
試したこと
Promise.all で自分なりに書いてみたが書き換えが上手く動作しない
補足情報(FW/ツールのバージョンなど)
Vue2系
回答1件
あなたの回答
tips
プレビュー