I have this code for uploading photo on server
photo: function () {
var self = this;
navigator.camera.getPicture(function
getPhotoTicket(function (ticket) {
var options = new FileUploadOptions();
var fileName = {};
options.fileKey = "upload_file";
try {
window.resolveLocalFileSystemURI(imageURI, onSuccess, onError);
} catch (e) {
console.log(e.toString());
fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1)+'.jpg';
}
options.fileName = fileName;
options.mimeType = "image/jpeg";
options.chunkedMode = false;
options.headers = {
Connection: "keep-alive"
};
options.httpMethod = "POST";
var params = {};
params.upload_ticket = ticket;
options.params = params;
function reload() {
getProfile(userID, function () {
app.profile_editor();
}, true);
}
function onSuccess(fileEntry) {
fileName = fileEntry.name;
}
function onError(fileEntry) {
fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1) + '.jpg';
}
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(URL + "api/index/fileupload"), function (success) {
alert('PHOTO UPDATED');
reload();
}, function (error) {
alert('error');
}, options);
});
}, function () {
console.log("error getting image")
}, {
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: navigator.camera.DestinationType.FILE_URI
});
}
it works fine on Android 4.3 and lower. But on Android KitKat i get imageURI like:
content://com.android.providers.media.documents/document/image%3A352
In this post Unable to load image when selected from the gallery on Android 4.4 (KitKat) using PhoneGap Camera Plugin MBillau suggest to set the destination type to DATA_URL. I tried but had no success. Could someone suggest how I need to refactor my code?