0

Hi when I try to use this.upload(); to call the upload function from a Cordova function I get this error enter image description here

The code is

/* This is the cordova function to access the phone camera */
cameraTakePicture() {
  navigator.camera.getPicture(this.onSuccess, this.onFail, {
  quality: 50,
  destinationType: navigator.camera.DestinationType.DATA_URL,
  });
}
onSuccess(imageData) {
  const image: any = document.getElementById('myImage');
  image.src = 'data:image/jpeg;base64,' + imageData;
  this.selected = imageData;
  }
 onFail(message) {
    alert('Failed because: ' + message);
}
/* Upload function I am trying to call */
  Upload() {
    const file = new FormData();
    if (this.selected != null) {
    this.loading = true;
    if (this.mobile === true) {
      document.querySelector('#output').scrollIntoView({ behavior: 'smooth', block: 'center' });
      }
    file.append('file', this.selected, this.selected.name);
    this.env.upload(file).subscribe(
      data => {
        this.data = data;
        this.loading = false;
      },
      error => {
        this.loading = false;
      }
    );
    } else {
      this.notifiy.showInfo('You need to choose a file first', 'Info');
    }
  }

im not sure how I can call this function any advice would be very helpful also if someone could explain why I am getting this error that would be great

isherwood
  • 58,414
  • 16
  • 114
  • 157
Conor Donohoe
  • 317
  • 1
  • 3
  • 18
  • Are you calling the update from the onSuccess callback? – yazantahhan Nov 05 '19 at 14:29
  • Yes it calls the onSuccess function then from there it calls the upload function but for some reason when I use the this. i get the error I don't understand why – Conor Donohoe Nov 05 '19 at 14:34
  • This is almost certainly a duplicate of [this question](https://stackoverflow.com/q/20279484/1009922). Try defining the callbacks as arrow functions: `onSuccess = (imageData) => { ... }`. – ConnorsFan Nov 05 '19 at 14:46

0 Answers0