我使用过cordova(navigator.camera.getPicture)从设备中捕获图像。我使用文件阅读器将fileURI转换为base64。但是,当我将base64 url指定为img src而如果我将相同的字符串传递给HTTP适配器(Worklight)时,我看到截断的编码数据。请帮忙。
提前致谢。
源代码:
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,
});
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)在Logcat中,tryToSend Fn中的编码完全打印,而下一行console.log提供截断的代码
// Ajax调用
答案 0 :(得分:1)
在我的logcat中,console.log一次只能打印大约4k个字符。因此,尝试比较编码的url的长度,以检查它是否真的被截断。