pstan
pstan

Reputation: 123

fetch filepicker file into arraybuffer in web browser

I'm trying to use filepicker.io to fetch binary data and pass it into a function like this:

var doSomething = function(arrayBuffer) {
    var u16 = new Int16Array(arrayBuffer);
}

I have no idea how to convert the binary into arraybuffer like this:

filepicker.getContents(url, function(data){
//convert data into arraybuffer
}

I tried to follow this tutorial on XMLHttpRequest but does't not work.

var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
    doSomething(this.response); 
};

Upvotes: 0

Views: 391

Answers (1)

Esailija
Esailija

Reputation: 140244

You are not calling .send with your XHR

xhr.send(null);

Upvotes: 1

Related Questions