Ionic 2 Photo upload error with cordova transfer plugin


#1

TypeError: Cannot read property ‘split’ of null(…)

i am getting this error while uploading the photo on server using cordova file transfer plugin.

Here is code for image picker

  ImagePick() {
    let options = {
      destinationType   : Camera.DestinationType.FILE_URI,
      sourceType        : Camera.PictureSourceType.PHOTOLIBRARY,
    };
    Camera.getPicture(options).then((imageData) => {
      // imageData is either a base64 encoded string or a file URI
      // If it's base64:
      this.Image = imageData;
      // this.getFileEntry(imageData);
      console.log(this.Image);
    }, (err) => {
      // Handle error
    });
  }

Here is code for File transfer plugin

 let options = {
      fileKey: "avatar",
      fileName: "image.jpg",
      mimeType: "image/jpeg",
      params: {
        food: this.navParams.get("food"),
        location_id: this.navParams.get("location"),
        address: this.navParams.get("address"),
        instructions: this.navParams.get("instructions"),
        phone: this.myForm.controls.phone.value,
          code: "b08d131e06",
        outlets_attributes: 'outlet'
      },
      headers: {headers: this.user_service.Get_Header()}
    };

    console.log(this.Image);
   let fileTransfer = new Transfer();
      if(this.Image!=null && this.Image!=""){
          console.log(this.Image);
            fileTransfer.upload(this.Image, URL, options).
            then((data) => {
              console.log(data);
            }, (err) => {
              console.log(err);
            });
      }

Need help regarding that issue. Thanks!


#2

I cant see where you are using split in your code. Anyways this article explain more on how to use the plugin http://www.developerslearnit.com/2016/11/build-photo-gallery-app-with-ionic2.html