1
votes

Trying to upload image with cordova file transfer plugin with following code snippet.

var params =  {
    token: credentials.token
}
var options = new FileUploadOptions();
options.fileKey = 'round';
options.fileName = 'round.jpg';
options.mimeType = "image/jpeg";
options.headers = {
    Connection: "close"
};
options.params = params;
var ft = new FileTransfer();
ft.upload(croppedImageURL, encodeURI(globals.nodeAppBase + 'v1/users/upload-user-picture'), function(){
    console.log("Successfully updated Round Image");
}, function (err) {
    console.log('There was an error uploading the media. Please try again later. Error: ' , err);
}, options, true);

But i am getting error:

{"code":3,"source":"file:///data/user/0/com.app.package/68-image.jpg","target":"https://api.server.com/v1/users/upload-user-picture","http_status":null,"body":null,"exception":"Chain validation failed"}

I tried till now:

  1. Add connection params in headers of options:

options.headers = { Connection: "close" };

2.Add true in as last param of Upload Function.

Still getting error as above mentioned.

2

2 Answers

0
votes

A couple of things come to mind to check:

  1. <access origin="https://api.server.com" /> or similar in config.xml.
  2. Make sure your SSL certificate chain on your server is valid. e.g. Not self-signed.
0
votes

Set Android SDK Version in config.xml to 27 worked for me using [email protected]

<preference name="android-targetSdkVersion" value="27" />

Notice, that if you update cordova-android to >= 7.0.0 you are dropping support for any android versions older than 5.0.0. See here for more details.