1

I'm using AngularFireStorage to build a upload image service. And have a problem.

Can't anybody show me the way to subscribe downloadurl? Here is my service:

This service may be worng?

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() 
       })
    )       
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

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

Been working at this for a while reading the same Documentation, when I realized it over complicates it.

Jonathan
  • 3,893
  • 5
  • 46
  • 77