Javascript 将多个文件上载到Firebase存储,所有上载完成后,订阅forkJoin

Javascript 将多个文件上载到Firebase存储,所有上载完成后,订阅forkJoin,javascript,angular,firebase,file-upload,firebase-storage,Javascript,Angular,Firebase,File Upload,Firebase Storage,我正在制作一个上传表单,需要上传所有文件,当所有上传完成后,我想订阅它们并触发下一个操作 我当前的实现不起作用: private uploadImages(): Observable<Subscription> { const uploadImages$: Subscription [] = []; this.testResponse.answers.forEach(answer => { const filePath = `${answer.selectedImage.

我正在制作一个上传表单,需要上传所有文件,当所有上传完成后,我想订阅它们并触发下一个操作

我当前的实现不起作用:

 private uploadImages(): Observable<Subscription> {
const uploadImages$: Subscription [] = [];
this.testResponse.answers.forEach(answer => {
  const filePath = `${answer.selectedImage.name.split('.').slice(0, -1).join('.')}_${new Date().getTime()}`;
  uploadImages$.push(this.testService.uploadPhoto(filePath, answer.selectedImage).subscribe((url: string) => {
      answer.imageUrl = url;
      delete answer.selectedImage;
      delete answer.id;
    }));
});
return forkJoin(uploadImages$);}

  public uploadPhoto(filePath: string, selectedImage?: UploadMetadata): Observable<string | UploadTaskSnapshot> {
return this.storage.upload(filePath, selectedImage).snapshotChanges().pipe(finalize(async () => this.getDownloadUrl(filePath))); }



  public getDownloadUrl(filePath: string): Observable<string> {
return this.storage.ref(filePath).getDownloadURL(); }
private uploadImages():可观察{
const uploadImages$:订阅[]=[];
this.testResponse.answers.forEach(answer=>{
const filePath=`${answer.selectedImage.name.split('.').slice(0,-1).join('.')}{new Date().getTime()}`;
uploadImages$.push(此.testService.uploadPhoto(文件路径、答案、选择图像)。订阅((url:string)=>{
answer.imageUrl=url;
删除答案。选择图像;
删除answer.id;
}));
});
返回forkJoin(uploadImages$);}
公共上传照片(文件路径:字符串,SelecteImage?:上传元数据):可观察{
返回此.storage.upload(filePath,selectedImage).snapshotChanges().pipe(finalize(async()=>this.getDownloadUrl(filePath));}
publicGetDownloadURL(文件路径:字符串):可观察{
返回此.storage.ref(文件路径).getDownloadURL();}
1.在管道中提供下载URL之前,“我如何等待”(finalize(async()…)


2.对于使用Angular将文件上载到Firebase,您是否有更好的实现方案?

希望这就是您试图实现的目标:

forkJoin(uploadImages$).pipe(
  map((photos) => {
    return photos.map(p => p.url);
  }),
  switchMap((photoUrls) => {
    return forkJoin(photoUrls.map(photoUrl => this.getDownloadUrl(photoUrl)));
  })
)
.subscribe((downloadUrls) => {
  console.log(downloadUrls);
});