Skip to content

AngularFire Storage Upload in Service-trying to get the Download Url after upload #2881

Answered by dooziiinc
dooziiinc asked this question in Q&A
Discussion options

You must be logged in to vote

So I ended up making a few changes that seem to work nicely:

export class StorageService{
...
downloadUrl$: BehaviorSubject<string> = new BehaviorSubject<string>('');
...
uploadFile(file:File):Observable<number | undefined> {
    
    const filePath = this.basePath;
    const fileRef = this.afStorage.ref(filePath);
    const uploadTask = this.afStorage.upload(filePath, file);

    uploadTask.snapshotChanges().pipe(
        finalize(() => {
          fileRef.getDownloadURL().pipe(map(res =>{
            this.downloadUrl$.next(res);  
          })).subscribe();
        })
     )
    .subscribe();
    return uploadTask.percentageChanges();
  }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dooziiinc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant