1

我正在使用 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() 
       })
    )       
}
4

1 回答 1

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

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

于 2018-06-03T06:45:57.323 回答