Trouble to upload images with FileTransfer

Hi,

I’m trying to add a function to my application which allow the user to take a picture with his camera or from his smartphone to upload it as a profil picture.

I’ve picked this function from another project which is working great but isn’t from me but one of my colleague (he left).

I don’t know why since I’ve used the exact same function but the image uploaded look like this :

5a1fd1a89a6f09412b6a74d75a1fd1a89a6f09412b6a74d7.jpg

It will randomly start to corrupt the file, generally in the first quarter. One time, it worked but I can’t figure why.

  takePhoto(value){
   
    const options: CameraOptions = {
      quality: 75,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
      correctOrientation : true,
      allowEdit:true,
      targetWidth: 300,
      targetHeight: 300,
      sourceType : value
      

    }
    
    this.camera.getPicture(options).then((imageData) => {
      // imageData is either a base64 encoded string or a file URI
      // If it's base64:
      let base64Image = 'data:image/jpeg;base64,' + imageData;
      console.log(base64Image)
      //$("#imgProfil").attr("src",base64Image);
      
      const fileTransfer: FileTransferObject = this.transfer.create();
    
      this._zone.run(() => {
      this.avatar_path = base64Image;      
      });

    var targetPath = base64Image;
      var options = {
          fileKey: "avatar",
          fileName: this.user._id + ".jpg",
          chunkedMode: false,
          mimeType: "image/jpeg",
          headers: {
              //Connection: "close"
          }
      };
      
    fileTransfer.upload(targetPath,"http://XX.XXX.XXX.XX:90/add/photoandroid/" + this.user._id, options) .then((data) => {
      this.storage.set('photoProfilData',base64Image);
      this.events.publish('photoProfil');

      }, (err) => {

      })
      
      }, (err) => {
        this.presentToasti(err);
    });
  }