TVML TVJS - download data from http server as binary

Hello,


I'm trying to download a file from a remote server for an application written using the TVML kit.


function downloadFile(path)

{

var xmlhttp = new XMLHttpRequest();

xmlhttp.open("GET", path, false);

xmlhttp.responseType = "blob";

xmlhttp.send();

return xmlhttp.response;

}


The xmlhttp.response is IKJSBlob kind of object. I've searched Apple's TVML documentation and there is no information about it.


Does anyone familiar with a method to do it properly?


Thanks

Have you tried using arraybuffer?

xmlhttp.responseType = 'arraybuffer';

It seems to be working, I have tried it myself. After the request was completed, you'll get an object of NSConcreteMutableDataas xmlhttp.response object.

And how can I convert it to a javascript array? I need to loop through the bytes, like this javascript example:



https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data


var oReq = new XMLHttpRequest();
oReq.open("GET", "/myfile.png", true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent)
{
     var arrayBuffer = oReq.response; // here is should be normal js array not "NSConcreteMutableData"
     if (arrayBuffer)
      {
          var byteArray = new Uint8Array(arrayBuffer);
          for (var i = 0; i < byteArray.byteLength; i++)
          {
          }
     }
};
oReq.send();
TVML TVJS - download data from http server as binary
 
 
Q