I'm trying to read a byte array from an Image using XMLHttpRequest:
var xhr = new XMLHttpRequest();
xhr.responseType = "blob"; // arraybuffer
xhr.onabort = function() {
};
xhr.onerror = function () {
console.log( xhr.error );
};
xhr.onloadend = function () {
};
xhr.onloadstart = function () {
};
xhr.ontimeout = function () {
console.log( "Request timed out after " + xhr.timeout );
};
xhr.onload = function () {
console.log( xhr.getAllResponseHeaders () );
console.log( xhr.metrics );
console.log( xhr.response );
if(xhr.response) {
localStorage.setItem("mxm_image_arraybuffer", xhr.response);
}
callback(xhr.response);
};
/xhr.addEventListener("load", function() {
console.log( "RESPONSE ");
console.log( xhr.getAllResponseHeaders () );
console.log( xhr.response );
callback(xhr.response);
}, false);*/
xhr.open("GET", path, 0); //async 0, sync 1
xhr.send(null);
I have several problems here:
I'm not sure if the responseType is "blob", since normally in JavaScript it woud be "arraybuffer"; In a ordinary JavaScript it is as simple as
var xhr = new XMLHttpRequest();
xhr.open("GET", path, true);
xhr.responseType = "arraybuffer";
xhr.onload = function() {
callback(xhr.response);
};
xhr.send(null);
Assumed that the closest thing to binary is blob, I make the request with that, but I cannot access this response object:
IKJSBlob
This is tvOS native object, but it seems it does not expose its implementation. For my knowledge, the native ObjC object should have a "data" property of type NSData, but I have no access to this, likely it's not a JSExport, so I cannot do anything with it.