XHR onprogress and binary data

1,184 views
Skip to first unread message

mlimper

unread,
Jun 10, 2013, 8:46:02 AM6/10/13
to chromiu...@chromium.org
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?

I guess this is a feature which is currently wanted by many people. The mozilla blog (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) states that one can receive intermediate results when using XHR with binary blobs:
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

Takeshi Yoshino

unread,
Jun 10, 2013, 9:32:15 AM6/10/13
to mlimper, Chromium HTML5
It conforms to the XHR spec. https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-response-attribute. We need to discuss this on the spec mailing list first.


Now, we started implementing the streaming extension experimentally which was mentioned in the w3c bug. See this thread, please.

Thanks
 
Best Regards,
Max

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-html...@chromium.org.
To post to this group, send email to chromiu...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.
 
 

mlimper

unread,
Jun 10, 2013, 10:52:53 AM6/10/13
to chromiu...@chromium.org, mlimper
Thanks a lot for the quick reply!
I didn't know Mozilla's "moz-chunked-arraybuffer" yet, but I have experimented with it a little bit.
It seems not the best solution that one always gets only the new incoming parts of the data as separate arraybuffers (instead of the first n bytes of the final result), but it is definitely useful.

The chromium feature request you mentioned is really similar to what I wanted, and I really appreciate your work on this issue!

Thanks again!
Reply all
Reply to author
Forward
0 new messages