cordovaionic-frameworkcordova-pluginscordova-3ngcordova

Cordova Plugin File Transfer using HTTPS


Here's my function which I used to transfer image to server. It was working with http url now it gives exception on https url. I think because cordova file transfer plugin supports only http and not https. Can any one help me get this working on https because other things depend on it.

  public uploadImg(img, userId) {
/*if (credentials.email === null || credentials.password === null || credentials.name === null) {
  return Observable.throw("Please insert credentials");
} else {*/
// At this point store the credentials to your backend!
console.log(userId);
let options: FileUploadOptions = {
  fileKey: 'img',
  fileName: 'name.png',
  params: {action: 'upload_image', api_key: API_KEY, user_id: userId},
  httpMethod: 'post',
  mimeType: 'image/png'
}
console.log('upload function');
return new Promise(resolve => {
  this.fileTransfer.upload(img, encodeURI('https://exampledomain.com/api/api.php'), options)
    .then((data) => {
      console.log('uploaded image');
      console.log('APi response is' + data.response);

      let img = JSON.parse(data.response);
      console.log(img.status + ' ' + img.message);
      resolve(img)
      // success
    }, (err) => {
      console.log('image failed');
      reject(false)
      // error
    });
});
// } }

Thanks


Solution

  • This topic helped me and I found the solution finally. I am answering this question so it could help someone. You need to add this chunkedMode=false param in options then it will work with https too. cheers!