0

我有一个将两个图像上传到 Firebase 存储的功能。上传工作得很好。

  const smallTaskRef = this.storage.upload(thumbPath, results.thumb);
  const largeTaskRef = this.storage.upload(largePath, results.large);

但是,在同一个函数中,我有下面的片段,我想用下载 URL 更新 firestore。检查存储后,两个图像都成功地存在。一旦它到达下面的代码片段,什么都不会发生。有什么可以用下面的方法来修复以确保可以设置 firestore 文档吗?

   const ref = combineLatest([smallTaskRef, largeTaskRef]).pipe(            
        switchMap(async() =>  {
          const smallimageURL = await smallTaskRef.getDownloadURL().toPromise();
          const largeImageURL = await largeTaskRef.getDownloadURL().toPromise();
          return this.afs.collection(`col`).doc(`${id}`).set({
            url_small: smallimageURL,      
            url_large: largeImageURL,    
          }).then(() => {
            console.log('successfully written')
          })
        })
      );

更新

const obs$ = combineLatest([thumbTask, largeTask]);

this._subscription = obs$.pipe(
   switchMap(async ([smallTaskRef, largeTaskRef]) => {
     const smallimageURL = await smallTaskRef.getDownloadURL().toPromise();
     const largeImageURL = await largeTaskRef.getDownloadURL().toPromise();
     return this.afs.collection(`col`).doc(doc).set({  
        // set doc values
     }).then(() => {
       console.log('successfully written')
     })
   })
).subscribe();
4

0 回答 0