I need to upload a large (> 100 MB) data file through XmlHttpRequest. The data is from a third party, and I would like to gradually display the content as it is downloaded.
So, I thought the following would work:
var req = new XMLHttpRequest();
req.open( "GET", mirror.url, true );
req.responseType = "arraybuffer";
req.onload = function( oEvent ) {
console.log( "DONE" );
};
var current_offset = 0;
req.addEventListener("progress", function(event) {
if( event.lengthComputable ) {
var percentComplete = Math.round(event.loaded * 100 / event.total);
}
var data = req.response;
var dataView = new DataView( data );
while( current_offset < dataView.byteLength ) {
++current_offset;
}
console.log( "OFFSET " + current_offset + " [" + percentComplete + "%]" );
}, false);
try {
req.send( null );
} catch( er ) {
console.log( er );
}
Unfortunately, according to the specification, .responsenot available.
Is there a way to access already downloaded data without resorting to such horrible workarounds as usage Flash?
EDIT:
Found at least a working custom solution for Firefox:
responseType = "moz-chunked-arraybuffer";
See also: WebKit equivalent to moz-chunked-arraybuffer "xhr responseType
source
share