首页 > 解决方案 > 从自定义服务订阅下载地址

问题描述

我正在使用 AngularFireStorage 构建上传图像服务。并且有问题。

没有人能告诉我订阅downloadurl的方法吗?这是我的服务:

这项服务可能会磨损?

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() 
       })
    )       
}

标签: javascriptfirebasefirebase-storageangularfire5

解决方案


  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();

当我意识到它过于复杂时,一直在阅读相同的文档。


推荐阅读