【问题标题】:Getting download URL for Firebase Storage for Angular 2+获取 Angular 2+ 的 Firebase 存储的下载 URL
【发布时间】:2021-08-22 11:16:47
【问题描述】:
ref: AngularFireStorageReference;
task: AngularFireUploadTask;
uploadState: Observable<string>;
uploadProgress: Observable<number>;
downloadURL: Observable<string>;

upload(event) {
  const id = Math.random().toString(36).substring(2);
  this.ref = this.afStorage.ref(id);
  this.task = this.ref.put(event.target.files[0]);
  this.uploadState = this.task.snapshotChanges().pipe(map(s => s.state));
  this.uploadProgress = this.task.percentageChanges();
  this.downloadURL = this.task.downloadURL();
}

以上来自guide

我希望这会在上传完成到 Firebase 存储后获得下载 URL。但我得到这个错误:

TS2740:“Subscription”类型缺少“Observable”类型的以下属性:_isScalar、source、operator、lift 等 6 个。

【问题讨论】:

    标签: angular typescript firebase firebase-storage angularfire2


    【解决方案1】:

    解决方案:

    upload(event) {
      const id = Math.random().toString(36).substring(2);
      const file = event.target.files[0];
      const filePath = id;
      this.ref = this.afStorage.ref(id);
      this.task = this.afStorage.upload(filePath, file);
      this.uploadState = this.task.snapshotChanges().pipe(map(s => s.state));
      this.uploadProgress = this.task.percentageChanges();
      this.task.snapshotChanges().pipe(
        finalize(() => this.downloadURL = this.ref.getDownloadURL() )
      ).subscribe()
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-08
      • 1970-01-01
      • 2018-12-28
      • 2018-07-04
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      相关资源
      最近更新 更多