I am building an android application using apache cordova framework.
In android 4.4 won't work as described in following issue
https://issues.apache.org/jira/browse/CB-5294
For that I am using below filechooser plugin
https://github.com/don/cordova-filechooser
Till now I am able to open file chooser dialog and select the file.
When I try to upload the file using following code
var def = Q.defer();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = file.substr(file.lastIndexOf('/') + 1);
var params = {};
params.title = title;
options.params = params;
options.trustAllHosts = true;
var ft = new FileTransfer();
var url = Constants.API_SERVICE_URL + "upload";
ft.upload(file, encodeURI(url), function(res) {
// check for HTTP OK status and success
if(res.responseCode === 200 && res.response && res.response.status !== "fail") {
def.resolve(res.response);
} else {
def.reject(res);
}
def.resolve(res);
}, function(err) {
def.reject(err);
}, options);
return def.promise;
The file here would be something like
content://com.android.providers.media.documents/document/image:28029
I got java.lang.SecurityException
I did so much research on the topic, but I am not able to find answers.
This issue is described here https://issues.apache.org/jira/browse/CB-5398
The issue there is marked as resolved, but the workaround described in this comment is not working
https://issues.apache.org/jira/browse/CB-5398?focusedCommentId=13977552&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13977552
If I do that I am getting file not found exception, the file url is like
file://storage/emulated/0/images/image.png
The below stackoverflow question is related
Kitkat, error while trying to load an image
The question has an answer, I tried that also but that is also not working.
I added MANAGE_DOCUMENTS permission in my android manifest file List of all permissions
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
But if I choose the file from gallery option or old file manager. It is working fine.
Any idea of how I can resolve this ?
EDIT:
Apache cordova version 3.6