0

I am working with firebase and angular. I want to upload files with this function, it works perfectly but i get error when i want to save the URL of the file uploaded in the variable fileUrl

ERROR TypeError: Cannot set property 'fileUrl' of undefined

i think it is a problem of parsing between fileUrl and downloadURL

fileUrl:string;

uploadFile(file: File) {

return new Promise(
  (resolve, reject) => {

    const almostUniqueFileName = Date.now().toString();
    const upload = firebase.storage().ref().child('ProfileImage/' + almostUniqueFileName + "xx").put(file);

      upload.on(firebase.storage.TaskEvent.STATE_CHANGED,
        (snapshot) => {
            console.log('Chargement…');
            this.progress = (upload.snapshot.bytesTransferred / upload.snapshot.totalBytes) * 100;
        },
        (error) => {
          console.log('Erreur de chargement ! : ' + error);
          reject();
        },

      () => {
        upload.snapshot.ref.getDownloadURL().then(function(downloadURL) {

          console.log(downloadURL);

          this.fileUrl = downloadURL;

          console.log(this.fileUrl);

        });

        resolve(upload.snapshot.downloadURL);

      }
    );
  }
);
}

help me please

user184994
  • 16,798
  • 1
  • 38
  • 48

0 Answers0