2012-05-24 17 views
5

Todavía luchando después de muchos intentos para leer la respuesta de un httprequest que es un flujo de datos binarios que representará una imagen jpg.httprequest y datos binarios en javascript

edición: todo el asunto

xmlhttp = false; 
     /*@[email protected]*/ 
     /*@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; 
      } 
     } 
     @[email protected]*/ 
     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); 

estoy usando IE8, y no HTML 5 (también tratado en FF12) así que siempre terminan con errores con algo así como

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

o

xhr.responseType = "arraybuffer"; 

incluso copiar en una obra postulante no variable de

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

any ideas ¿qué hay de malo o qué puedo probar?

+0

¿Por qué? ¿Qué está tratando de lograr? ¿Puede su servidor hacer una codificación b64? – mplungjan

+0

no es un dispositivo incrustado y la compañía no cambiará su interfaz tristemente – Gobliins

+0

Pero entonces, ¿cómo se supone que debes usar los datos binarios en el lado del script? – Raffaele

Respuesta

1

Hice this example para leer JPEG binario en el lado del cliente y analizar datos EXIF. Utiliza BinFileReader.js, lo que hace que sea realmente fácil tratar con datos binarios, entre navegadores. Here is the whole thing in a zip file, incluido un servidor web basado en nodo (ejecutar con nodo server.js) Incluí un web-worker example, también.

Si solo está haciendo una imagen de transmisión binaria, ¿por qué no simplemente agrega <img src="blah" /> a su DOM?

$('body').append('<img src="' + URL + '"/>'); 
+0

¿Responde esto a su pregunta? – konsumer

Cuestiones relacionadas