0
votes

How i can retrieve my url value in the reactive form ? I dont know how to extract value from Observable to be returned by function in which Observable is present. I need just a value from it to be returned, nothing else.

uploadFile(event) {
    const file = event.target.files[0];
    const filePath = Date.now().toString();
    const fileRef = this.storage.ref('/referentiels/' + filePath);
    const task = this.storage.upload('/referentiels/' + filePath, file);
    this.uploadPercent = task.percentageChanges();
     task.snapshotChanges().pipe(
        finalize(() => {
       this.downloadURL = fileRef.getDownloadURL();
       this.downloadURL.subscribe((url) => {
            return url
        });
        }))
    .subscribe()
  }    
  onSaveReferentiel() {
    const nomSS = this.referentielForm.get('nomSS').value;
    const speSS = this.referentielForm.get('speSS').value;
    const webSS = this.referentielForm.get('webSS').value;
    const newReferentiel = new Referentiel (nomSS, speSS, webSS, ---url---);
    this.referentielsService.createNewReferentiel(newReferentiel);
    this.router.navigate(['/referentiels']); 
  }
1
what do you want to achive?Chellappan வ
currently what error are you getting?Chellappan வ
are you getting back any value try to console the subscribed data?Chellappan வ
I had reformulated my questionNewbiiiie

1 Answers

1
votes

Try this

uploadFile(event) {
    const file = event.target.files[0];
    const filePath = Date.now().toString();
    const fileRef = this.storage.ref('/referentiels/' + filePath);
    const task = this.storage.upload('/referentiels/' + filePath, file);
    this.uploadPercent = task.percentageChanges();
   task.snapshotChanges().pipe(
    finalize(() => {
   this.downloadURL = fileRef.getDownloadURL();
   this.downloadURL.subscribe(url => this.url = url
    );

    }))
.subscribe())

}