Hi,
I'm downloading binary data via XHR, and I want to have access to the intermediate stages of the data during download (i.e., I want progressive streaming with binary data).
It looks like there has already been some discussion about this topic:
https://groups.google.com/a/chromium.org/forum/#!searchin/chromium-html5/onprogress$20arraybuffer/chromium-html5/VVVztYZgbUM/X-XAmE3HSCAJ
However, I have not yet been able to find a working solution. I've tried both, 'blob' as well as 'arraybuffer' as response type, and the problem is always that I cannot access the data until it has been fully downloaded. I am using the following callback function for the onprogress event, with the return type of the XHR set to 'arraybuffer':
function cb_progress(event)
{
if (event.lengthComputable) {
console.log('Progress! ' + (100*(event.loaded / event.total)).toFixed(2) + " % Loaded. "
+ 'ArrayBuffer Length (Bytes): ' + (request.response ? request.response.byteLength : 'Not Available'));
}
}
The log will always look like this:
Progress! 0.26 % Loaded. ArrayBuffer Length (Bytes): Not Available
[...]
Progress! 96.88 % Loaded. ArrayBuffer Length (Bytes): Not Available
Progress! 100.00 % Loaded. ArrayBuffer Length (Bytes): 12582912
Obviously, although the size of the intermediate stages of the buffer is always available, I am not allowed to access it until it has been fully loaded. The same applies if I set the return type to 'blob'.
Any ideas whether this problem could be solved with current chrome features?
If your progress event is called with a responseType
of "moz-blob", the value of response is a Blob
containing the data received so far. However, testing the above code in Firefox with the return type set to 'blob' or 'moz-blob' results in just a single onprogress event (as soon as 100% have been loaded), so that's pretty much the same result as in Chrome.
So, I'm really wondering what's the current state of development for streaming binary data. Any hint is appreciated- thanks a lot in advance.
Best Regards,
Max