TypeError: Can not read property 'files' of undefined

0

I have the following code snippet for uploading firebse storage I'm using typescript.

uploadPhoto(photo) {
//Get File
this.file = photo.files[0]; // Erro nessa linha

this.metadata = {
  'contentType': this.file.type
};

//Create a storage ref
this.storageRef = firebase.storage().ref().child('images/');

// Upload file
this.storageRef.put(this.file, this.metadata);

}

It gives the following error:

TypeError: Cannot read property 'files' of undefined
    
asked by anonymous 13.12.2016 / 14:26

1 answer

0

This type of error TypeError: Cannot read property 'files' of undefined usually occurs because the value is lost, either by not passing the parameter or because it was not obtained or set. If you go through the code from the beginning, you will realize that at some point this value has been lost.

    
13.12.2016 / 15:57