3
對於應該從相機或文件系統上傳圖像的網頁,我有以下代碼,然後在將它作爲JSON發送之前將其轉換爲字符串要求。:Javascript代碼適用於桌面,但不適用於手機
var fileToLoad = new Blob([images[0]], {
type: 'image/tif'
});+
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent) {
var srcData = fileLoadedEvent.target.result; // <--- data: base64
var divTest = document.getElementById("imgTest");
var newImage = document.createElement('img');
newImage.src = srcData;
imageString = newImage.outerHTML;
//<img src="data:image/tif;base64,SUkqAAgAAAATAP4ABAABAAAAAAAAAAABBAABAAAAsAQAAAEBBAABA…71sXFsbHw8F/BP6Hr9+JZlWf//+1UVYRmCIUOFbllbXhaaSzELdERERERERET8//////8/AAIg">
imageString = imageString.substring(32, imageString.length-2); //The above returns a string for <img src.......>. So this line removes the html stuff to leave just the image string
console.log(imageString);
var testJSON =
{
"jobWithDocsInitialization": {
"InputVariables": [{
"Id": "InputVar",
"Value": "Conor"
}],
"RuntimeDocumentCollection": [{
"Base64Data": null,
"Data": null,
"DeleteDocument": true,
"DocumentGroup": {
"Id": null,
"Name": "",
"Version": 0
},
"DocumentName": "",
"DocumentTypeId": null,
"FieldsToReturn": null,
"FilePath": null,
"FolderId": null,
"FolderTypeId": null,
"MimeType": null,
"PageDataList": [{
"Data": null,
"Base64Data": imageString,
"MimeType": "image/tiff",
"RuntimeFields": {}
}],
"PageImageDataCollection": null,
"ReturnAllFields": true,
"RuntimeFields": null
}],
"StartDate": null
},
"processIdentity": {
"Id": null,
"Name": "DriversLicRTTI",
"Version": 10
},
"sessionId": "C640521793431F4486D4EF1586672385",
"variablesToReturn": {"id":"loopIndex"}
};
ajax.send(JSON.stringify(testJSON));
}
fileReader.readAsDataURL(fileToLoad);
上面的代碼將在圖像被選中時調用。在發送JSON請求之前,它會將所選圖像更改爲字符串。它應該能夠在桌面或移動設備上的網絡瀏覽器上運行。它在桌面上完美運行。我可以將我上傳的圖像轉換爲字符串,並將其發送到我的服務器沒有問題。
但是,當我在手機上做同樣的事情時,我收到一個錯誤,說錯誤處理請求:未定義。
沒有Chrome調試器,這是一個巨大的幫助,以及像機器上的Fiddler這樣的東西,有沒有什麼方法可以找到可能出錯的東西?我真的不知道如何在手機上攻擊這個問題。
您可以隨時使用Firebug精簡版對大家有點幫助調試:https://getfirebug.com/firebuglite_mobile – TbWill4321
在Android上,您可以使用遠程調試:https://developer.chrome.com/devtools/docs/remote-debugging – jan
乾杯小夥子們。該Chrome調試器看起來很完美。 Firebug也不錯,但在我的手機上有點小。 – discodowney