function upload(blobOrFile) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/server', true);
xhr.onload = function(e) { ... };
xhr.send(blobOrFile);
}
document.querySelector('input[type="file"]').addEventListener('change', function(e) {
var blob = this.files[0];
const BYTES\_PER\_CHUNK = 1024 \* 1024; // 1MB chunk sizes.
const SIZE = blob.size;
var start = 0;
var end = BYTES\_PER\_CHUNK;
while(start \< SIZE) {
upload(blob.slice(start, end));
start = end;
end = start + BYTES\_PER\_CHUNK;
}
}, false);
})();