I have used cordova(navigator.camera.getPicture) to capture image from device. I converted the fileURI into base64 using file reader. But, when i assign the base64 url as img src whereas If i pass the same string to HTTP adapter(Worklight), I saw the encoded data truncated. Please help.
Thanks in advance.
Source Code:
function tryToSend(evt) {
encoding = evt.target.result;
console.log("Encoded File: "+encoding);
Ext.ComponentQuery.query('#encodedImage')[0].setHtml('<img style="height: 100px; width: 100px;" src="'+encoding+'" />');
Ext.ComponentQuery.query('#encodedImage')[0].setHidden(false);
}
function win(file) {
alert("FileName:"+file.name + ' & Type:' + file.type);
selectedFileName = file.name;
Ext.ComponentQuery.query('#originalImage')[0].setHtml('<img style="height: 100px; width: 100px;" src="'+file.fullPath+'" />');
Ext.ComponentQuery.query('#originalImage')[0].setHidden(false);
var reader = new FileReader();
reader.onloadend = tryToSend;
var encoded = reader.readAsDataURL(file);
}
function fail(error) {
console.log(error);
}
function onResolveSuccessCompleted(fileEntry) {
fileEntry.file(win, fail);
}
function onResolveFailed(error) {
console.log(error);
}
//Call on click of take pic button
function capPic(){
navigator.camera.getPicture(onCapturePhoto, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: Camera.PictureSourceType.CAMERA,
mediaType: navigator.camera.MediaType.ALLMEDIA,
});
}
//Success
function onCapturePhoto(fileURI) {
window.resolveLocalFileSystemURI(fileURI, onResolveSuccessCompleted, onResolveFailed);
fileDetails.push({
base64ImageData:encoding,
fileName: selectedFileName,
});
alert("File Selected. Please Upload Now");
}
//Sending fileDetails array to HTTP adapter as parameter
var invocationData = {
adapter : 'SAMPLE_ADAPTER',
procedure : 'uploadFileNow',
parameters : [fileDetails]
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : fileUploadOK,
onFailure : fileUploadFail,
});
1) In Logcat, encoding in tryToSend Fn prints completely whereas the next line console.log gives truncated code
//Ajax call
Ext.Ajax.request({
url: url,
method:'POST',
params:fileDetails,
success: function(response){
console.log(response);
},
failure:function(response){
console.log(response);
}
});