Search code examples
cordova-3

File options is not defined in cordova file transfer


My requirement is upload a file from device to server

I did same code on cordova version 2.6 its working but in 3.6 i am using same code its not working. Its saying file upload options is not defined.

var options = new FileUploadOptions();
 options.fileKey = "file";
 options.fileName = "test";

 var params = {};
 params.value1 = "test";
 params.value2 = "param";

 options.params = params;                   

 var ft = new FileTransfer();
 ft.upload("DbPath", encodeURI("ServerURL"), win, fail, options);  

Solution

  • Check your AndroidManifest.xml file. we have to give permission to read the file from phone.

    In cordova 2.6 this permission was by-default enabled, In cordova 3 onwards we have to add manually

    Add below tag in AndroidManifest.xml file

    uses-permission android:name="android.permission.READ_PHONE_STATE"

    Note : Only this was the issue. This is not related to any cordova versions