【问题标题】:subscribe downloadurl from custom service从自定义服务订阅下载地址
【发布时间】:2018-05-26 10:52:57
【问题描述】:

我正在使用 AngularFireStorage 构建上传图片服务。还有一个问题。

没有人能告诉我订阅下载网址的方法吗?这是我的服务:

这项服务可能会被磨损?

uploadImage(image): Observable<any> {

    const path = ...;       
    const fileRef = this.afStorage.ref(path);    
    const task = this.afStorage.upload(path, image);

    return task.snapshotChanges().pipe(
       finalize(() => {          
           return fileRef.getDownloadURL() 
       })
    )       
}

【问题讨论】:

  • 谁能帮帮我

标签: javascript firebase firebase-storage angularfire5


【解决方案1】:
  const task = this.storage.upload(path, file);
  const ref = this.storage.ref(path);
  this.uploadPercent = task.percentageChanges();
  console.log('Image uploaded!');
  task.snapshotChanges().pipe(
    finalize(() => {
      this.downloadURL = ref.getDownloadURL()
      this.downloadURL.subscribe(url => (this.image = url));
    })
  )
  .subscribe();

在阅读相同的Documentation 时一直在研究这个问题,当我意识到它过于复杂时。

【讨论】:

    猜你喜欢
    • 2021-07-03
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多