1

I have a binary file on a server and I want to read it.

I did something like that to get the file :

var request = new XMLHttpRequest();
request.open("GET", file);
request.onreadystatechange = function() {
    if (request.readyState == 4) {
        doSomething(request.responseText);
    }
}
request.send();

but after that I'm not really sure what to do... What is the proper way to do this ?

is there a way to use fileReader.readAsArrayBuffer() to do what I want to do ?

1 Answer 1

4

Set the responseType to arrayBuffer like so:

var request = new XMLHttpRequest();
request.open("GET", file);
request.responseType = 'arrayBuffer'; // the important part
request.onreadystatechange = function() {
  if (request.readyState == 4) {
      doSomething(request.mozResponseArrayBuffer || request.response); // your arrayBuffer
  }
}

request.send();
Sign up to request clarification or add additional context in comments.

2 Comments

nice and simple, perfect !
'arraybuffer' needs to be all lowercase apparently

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.