0

I have a function that's uploading two images to firebase storage. The uploads work perfectly fine.

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

However, within the same function i have the snippet below where I would like to update firestore with the download URLs. Upon checking storage, both images are successfully there. Once it reaches the snippet below, nothing happens. Is there anything that could be fixed with the below to ensure that a firestore document can be set?

   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')
          })
        })
      );

UPDATE

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();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Que
  • 957
  • 2
  • 14
  • 35
  • Are you subscribing to the ref observable somewhere after this? Unlike promises, observables won't run unless subscribed to. – harleybl Dec 03 '20 at 14:05
  • I wasn't! - I've made an update to the original post with an approach them seems to work. Is the approach taken ok "practise" / best practise? – Que Dec 03 '20 at 14:12

0 Answers0