Firebase .getDownloadURL() returns undefined in Angular

Viewed 45

I created function which on form submit to upload picture to Firebase storage.

The function is uploading the img successfuly but can't retrieve the proper url. It is returning 'undefined' for url property

function:

   constructor(
         public dbStorage: AngularFireStorage, 
    ) { }

Upload(event$) {
    this.selectedImg = $event.target.files[0];

    const car = {
                  photoURL: `/images/cars/${new 
                    Date().getTime()}-${this.selectedImg.name.split('.').slice(0,-1)}`,
                  photo: this.selectedImg,  
                  }
    const _photoURL = this.dbStorage.ref(car.photoURL);
    this.dbStorage.upload(car.photoURL, car.photo).snapshotChanges().pipe(
         finalize(()=>{
             _photoURL.getDownloadURL().subscribe((url) =>{
               car.photoURL = url;
            })
         })
    ).subscribe();
}
0 Answers
Related