Getting byte array through input type = file Getting byte array through input type = file javascript javascript

Getting byte array through input type = file


[Edit]

As noted in comments above, while still on some UA implementations, readAsBinaryString method didn't made its way to the specs and should not be used in production.Instead, use readAsArrayBuffer and loop through it's buffer to get back the binary string :

document.querySelector('input').addEventListener('change', function() {  var reader = new FileReader();  reader.onload = function() {    var arrayBuffer = this.result,      array = new Uint8Array(arrayBuffer),      binaryString = String.fromCharCode.apply(null, array);    console.log(binaryString);  }  reader.readAsArrayBuffer(this.files[0]);}, false);
<input type="file" /><div id="result"></div>