0

我已经使用 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,
    });

1) 在 Logcat 中,tryToSend Fn 中的编码完全打印,而下一行 console.log 给出了截断的代码

//Ajax调用 Ext.Ajax.request({ url: url, method:'POST', params:fileDetails, success: function(response){ console.log(response); }, failure:function(response){ console.log(response); } });

4

1 回答 1

1

在我的 logcat 中,console.log 一次只能打印大约 4k 个字符。所以尝试比较编码后的 url 的长度来检查它是否真的被截断了。

于 2015-08-12T03:14:12.173 回答