6

Still struggling after lots of tries to read the response of a httprequest that is a binary datastream which will represent an jpg image.

edit: the whole thing

xmlhttp = false;
        /*@cc_on@*/
        /*@if (@_jscript_version >= 5)
        // JScript gives us Conditional compilation, we can cope with old IE versions.
        // and security blocked creation of the objects.
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
        @end@*/
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            try {
                xmlhttp = new XMLHttpRequest();
            } catch (e) {
                xmlhttp = false;
            }
        }
        if (!xmlhttp && window.createRequest) {
            try {
                xmlhttp = window.createRequest();
            } catch (e) {
                xmlhttp = false;
            }
        }

        xmlhttp.open("GET", theUrl, true);  
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {

                var headers = xmlhttp.getAllResponseHeaders(); 
            }
        }

        xmlhttp.send(null);

I am using IE8, and no HTML 5 (also tried in FF12) so i always end up with errors with something like

xhr.overrideMimeType('text\/plain; charset=x-user-defined');

or

xhr.responseType = "arraybuffer";

even copying into a variable won´t work

var body = xhr.response; //.responseText , .responseBody

any ideas whats wrong or wwhat i could try?

6
  • Why? What are you trying to accomplish? Can your server do b64 encoding? Commented May 24, 2012 at 12:56
  • no its an embedded device and the company won´t change their interface sadly Commented May 24, 2012 at 12:59
  • But then how are you supposed to use the binary data on the script side? Commented May 24, 2012 at 13:02
  • the plan is to create the image out of the images data stream Commented May 24, 2012 at 13:06
  • 1
    You might want to look at this Commented May 24, 2012 at 13:08

1 Answer 1

1

I made this example to read binary JPEG on client-side and parse EXIF data. It uses BinFileReader.js which makes it really easy to deal with binary data, cross-browser. Here is the whole thing in a zip file, including a node-based webserver (run with node server.js) I included a web-worker example, also.

If you are just making an image out of binary stream, why not just add <img src="blah" /> to your DOM?

$('body').append('<img src="' + URL + '"/>');
Sign up to request clarification or add additional context in comments.

1 Comment

Does this answer your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.