discodowney
discodowney

Reputation: 1507

Javascript code works on desktop but not on mobile

I have the following code for a web page that is supposed to upload an image, from camera or file system, and then convert it to a string before sending it off with as a JSON request.:

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);

The code above will be called when an image is chosen. It will change a selected image to a string before sending it off in a JSON request. It should be able to run on a web browser on desktop or on mobile. It works perfectly on desktop. I can convert the image I upload to a string and send it off to my server no problem.

However when I do the same on my phone I get an error saying Error in processing request: undefined.

Without the Chrome debugger, which was a huge help, and things like Fiddler on the machine, is there any way to hunt down what might be going wrong? I dont really know how to attack this issue on the phone.

Upvotes: 3

Views: 2739

Answers (1)

discodowney
discodowney

Reputation: 1507

As per Jan's response to my question, the Chrome debugger for my Android phone worked perfectly. Solved my problem in no time.

https://developer.chrome.com/devtools/docs/remote-debugging

Upvotes: 1

Related Questions