首页 > 解决方案 > ref.getMetadata does not subscribe in AngularFireStorage

问题描述

I have recently updated to AngularFire 6.0 and I have been having issues with the AngularFireStorage. Once I upload an image and call ref.getMetadata().subscribe(...), there seems to be no data returning. Here is a snippet of my code:

this.ref = this.afStorage.ref(`${this.location}/tmp/${randomUUID}`);
this.task = this.ref.put(imageFile, { customMetadata: { blah: 'blah' } });
this.uploadProgress = this.task.percentageChanges();
this.task
  .snapshotChanges()
  .pipe(finalize(() => {
    this.ref.getMetadata().subscribe(
      (res: any): void => {
        imgControl.setValue(res.fullPath);
        imgControl.updateValueAndValidity();
        this.setPreviewSrc(imageFile);
        this.uploading = false;
      },
      (error: any): void => {
        console.error(error);
        this.error = true;
        this.errorMessage = 'Something went wrong. Please retry.';
      }
    );
  })
).subscribe();

I have tried calling this.ref.getDowloadUrl().subscribe(...) and that works. Let me know what I am missing.

标签: typescriptfirebasegoogle-cloud-firestorerxjsangularfire

解决方案


推荐阅读