New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 52486 link

Starred by 37 users

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Mar 2012
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug

Restricted
  • Only users with EditIssue permission may comment.



Sign in to add a comment

Implement XHR.responseType='blob'

Project Member Reported by michaeln@chromium.org, Aug 17 2010

Issue description

Implement an XHR.responseBlob accessor to get an opaque reference to the response data as a blob.

Two new additions for the XHR interface in support of this. This is not solidified yet, still pending some discussion on the public lists.

boolean attribute asBlob;
// Prepares the XHR to make the response available as a blob object.
// Defaults to false, must be set after calling open() and
// prior to calling send(). Gets reset upon subsequent calls to open().
// Throws INVALID_STATE_ERR if set at an invalid time. Maybe read at
// anytime without exception.

Blob attribute responseBlob;
// Returns a blob the contains the response body.
// Only valid to access when asBlob is true and when the request is in
// a terminal state. Throws INVALID_STATE_ERR if accessed at an
// invalid time.

When asBlob is true, the other response accessors (responseText, resonseXML, responseBody) throw INVALID_STATE_ERR if accessed.

We're making this "modal" for the benefit of the browser vendors, to make it easier for them to know how to handle the response data as it comes in. With a priori knowlege that the data need never be made available thru the responseText attribute, life is a little easier for them.

 
This should mostly involve webcore changes, I've opened a bug there for this was well
https://bugs.webkit.org/show_bug.cgi?id=44133

Comment 2 by bugdro...@gmail.com, Aug 25 2010

The following revision refers to this bug:
    http://src.chromium.org/viewvc/chrome?view=rev&revision=57376 

------------------------------------------------------------------------
r57376 | michaeln@chromium.org | 2010-08-25 13:28:13 -0700 (Wed, 25 Aug 2010) | 6 lines
Changed paths:
   M http://src.chromium.org/viewvc/chrome/trunk/src/build/features_override.gypi?r1=57376&r2=57375

Define XHR_RESPONSE_BLOB when building.

TEST=none
BUG= 52486 

Review URL: http://codereview.chromium.org/3185027
------------------------------------------------------------------------

Comment 3 by karen@chromium.org, Sep 3 2010

Status: Fixed
Status: Assigned
reopening, this feature is not yet implemented
Labels: Mstone-8

Comment 6 by bslat...@gmail.com, Sep 23 2010

Any ideas when this will land in the Chromium nightly?

Comment 7 Deleted

Comment 8 by mnord...@gmail.com, Sep 23 2010

I don't have an eta just yet, but this is what i'm actively working on. I'm working on the webcore side of things now. I'll update the bug when I know more.

Comment 9 by bugdro...@gmail.com, Sep 23 2010

The following revision refers to this bug:
    http://src.chromium.org/viewvc/chrome?view=rev&revision=60378

------------------------------------------------------------------------
r60378 | michaeln@chromium.org | Thu Sep 23 16:16:45 PDT 2010

Changed paths:
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/sync_resource_handler.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/async_resource_handler.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/tools/test_shell/test_shell.gypi?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/async_resource_handler.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_handler.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/weburlloader_impl.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/tools/test_shell/simple_resource_loader_bridge.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host.h?r1=60378&r2=60377&pathrev=60378
 A http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference_unittest.cc?r1=60378&r2=60377&pathrev=60378
 A http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/resource_dispatcher.cc?r1=60378&r2=60377&pathrev=60378
 A http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/resource_dispatcher.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/render_messages_internal.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/webkit_blob.gypi?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/redirect_to_file_resource_handler.h?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/net/blob_url_request_job_factory.cc?r1=60378&r2=60377&pathrev=60378
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc?r1=60378&r2=60377&pathrev=60378

Flesh out URLLoader's download_to_file function.
* tie the lifetime of the resulting temp file to the lifetime of the URLLoader
  (the plan is to later extend the lifetime of the temp file to support xhr.responseBlob)
* make it work in test_shell
* make it work for sync requests
* added OnDataDownloaded messages to report progress

A related BlobURL loading change.
* grab a reference to the blob early on to ensure it's still there when the 'job' is finally started.

TEST=manual and deletable_file_reference_unittest.cc
BUG= 52486 

Review URL: http://codereview.chromium.org/3165062
------------------------------------------------------------------------
The following revision refers to this bug:
    http://src.chromium.org/viewvc/chrome?view=rev&revision=60425

------------------------------------------------------------------------
r60425 | thakis@chromium.org | Thu Sep 23 22:19:13 PDT 2010

Changed paths:
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/sync_resource_handler.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/async_resource_handler.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/tools/test_shell/test_shell.gypi?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/async_resource_handler.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_handler.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/weburlloader_impl.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/tools/test_shell/simple_resource_loader_bridge.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host.h?r1=60425&r2=60424&pathrev=60425
 D http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference_unittest.cc?r1=60425&r2=60424&pathrev=60425
 D http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/resource_dispatcher.cc?r1=60425&r2=60424&pathrev=60425
 D http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/resource_dispatcher.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/render_messages_internal.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/webkit_blob.gypi?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/redirect_to_file_resource_handler.h?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/net/blob_url_request_job_factory.cc?r1=60425&r2=60424&pathrev=60425
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc?r1=60425&r2=60424&pathrev=60425

Revert 60378 (trying to track down  http://crbug.com/56752  )- Flesh out URLLoader's download_to_file function.
* tie the lifetime of the resulting temp file to the lifetime of the URLLoader
  (the plan is to later extend the lifetime of the temp file to support xhr.responseBlob)
* make it work in test_shell
* make it work for sync requests
* added OnDataDownloaded messages to report progress

A related BlobURL loading change.
* grab a reference to the blob early on to ensure it's still there when the 'job' is finally started.

TEST=manual and deletable_file_reference_unittest.cc
BUG= 52486 

Review URL: http://codereview.chromium.org/3165062

TBR=michaeln@chromium.org
Review URL: http://codereview.chromium.org/3455022
------------------------------------------------------------------------
The following revision refers to this bug:
    http://src.chromium.org/viewvc/chrome?view=rev&revision=60862

------------------------------------------------------------------------
r60862 | michaeln@chromium.org | Tue Sep 28 15:52:55 PDT 2010

Changed paths:
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/sync_resource_handler.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/async_resource_handler.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/tools/test_shell/test_shell.gypi?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/async_resource_handler.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_handler.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/weburlloader_impl.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/tools/test_shell/simple_resource_loader_bridge.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host.h?r1=60862&r2=60861&pathrev=60862
 A http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference_unittest.cc?r1=60862&r2=60861&pathrev=60862
 A http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/resource_dispatcher.cc?r1=60862&r2=60861&pathrev=60862
 A http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/deletable_file_reference.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/resource_dispatcher.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/render_messages_internal.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/redirect_to_file_resource_handler.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/webkit/blob/webkit_blob.gypi?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/redirect_to_file_resource_handler.h?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/net/blob_url_request_job_factory.cc?r1=60862&r2=60861&pathrev=60862
 M http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc?r1=60862&r2=60861&pathrev=60862

Flesh out URLLoader's download_to_file function.
* tie the lifetime of the resulting temp file to the lifetime of the URLLoader
 (the plan is to later extend the lifetime of the temp file to support xhr.responseBlob)
* make it work in test_shell
* make it work for sync requests
* added OnDataDownloaded messages to report progress

A related BlobURL loading change.
* grab a reference to the blob early on to ensure it's still there when the 'job' is finally started.

TEST=manual and deletable_file_reference_unittest.cc
BUG= 52486 , 56752 

Review URL: http://codereview.chromium.org/3396029
------------------------------------------------------------------------

Comment 12 by bslat...@gmail.com, Oct 10 2010

So where is this now? Still dying for this to work in Chrome.
Labels: -Mstone-8 Mstone-9
This is gated on getting some changes into webcore. I was shooting to have this in M8, but ran into some contention from the webkit folks.

https://bugs.webkit.org/show_bug.cgi?id=44722

We have a basic agreement about the shape of the answer now and i'll be revisiting that patch very soon.
Labels: -mstone-9 Mstone-10
Given our current velocity, we need to punt 500 bugs from m9.  Moving p2 bugs, that are not started and have an owner, to the next milestone.  If this issue absolutely needs to be fixed in the current milestone please move it back, however, at this time the focus should be on p1 bugs.

Comment 16 by kerz@chromium.org, Dec 9 2010

Labels: -Mstone-10 MovedFrom-10 Mstone-11
P2 bugs with an owner that are not marked as started are being automatically moved to mstone:11.
Is there any progress? Is there a dev build which features this?
@si...@simonheckmann.de

In m9 you can do something like this https://gist.github.com/809418, using responseType = "arraybuffer".

Comment 19 Deleted

Okay, this worked. But shouldn't [responseType = "blob"] also work? If yes, xhr.response should return a Blob-Object, right? [http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#the-response-attribute]. I should then be able to call xhr.response.size to get the number of downloaded bytes. Or do I get it wrong?
Yes it should work but currently it doesn't. I'am getting 

readyState: 4
response: null
responseText: Error: INVALID_STATE_ERR: DOM Exception 11
responseType: "blob"
responseXML: Error: INVALID_STATE_ERR: DOM Exception 11
status: 200
statusText: "OK"

To refresh memory:

INVALID_STATE_ERR code 11
Attempted to use an object that is not useable; this error is generally only thrown by an implementation when it's not able to perform a specific operation for internal reasons.

I believe that because blob currently isn't supported, but you can still construct him manually. You can get size with

blob.getBlob().size

 



Comment 22 by kareng@google.com, Mar 9 2011

Labels: -Mstone-11 MovedFrom-11 Mstone-12
rolling non releaseblocker mstone 11 bugs to mstone 12. 

Comment 23 by k...@google.com, Apr 25 2011

Labels: -Mstone-12 Mstone-13 MovedFrom12
Moving out of M12.

Comment 24 by ise...@gmail.com, May 4 2011

Is there a workaround for now?
If you managed to force javascript to receive the data as a string in a character set agnostic mode, you could turn that into character codes, do a binary AND with each character code and 0xff and then feed the resulting integers into BlobBuilder. I think this way you might be able to recreate the original blob. If you do not need a blob specifically, there are probably easier ways to do this.
/*=================================================================================
 getFile(string url, function callback)

 downloads a file

 parameters
             url: (required) URL of the file to download and encode
        callback: (required) where to send the downloaded file

 returns
        nothing
=================================================================================*/
function getFile(url, callback) {
    var xhr = new XMLHttpRequest();

    xhr.open('GET', url, true);
    xhr.overrideMimeType('text/plain; charset=x-user-defined');
    xhr.responseType = 'arraybuffer';

    xhr.onload = function(e) {
        var blob = new WebKitBlobBuilder();

        blob.append(xhr.response);

        callback(blob.getBlob());
    };

    xhr.send(null);
}

Working sample, you can also use webkitURL, to create DOMURL for that blob. 
example:
getFile("http://www.google.com/images/nav_logo65.png",function(blob){
   console.log(webkitURL.createObjectURL(blob))
})
@toni, the point of xhr.responseType =  'blob' is so we don't have to use char code manipulation.
Typed arrays ftw :)

@janez, you don't need the xhr.overrideMimetype. That's what xhr.responseType = 'arraybuffer'  gives us:

====
var xhr = new XMLHttpRequest();
xhr.open('GET', '/path/to/image.png', true);

xhr.responseType = 'arraybuffer';

xhr.onload = function(e) {
  if (this.status == 200) {

    // Create a uInt8 container from the response:
    var uInt8Array = new Uint8Array(this.response); // Note: not xhr.responseText
    for (var i = 0, len = uInt8Array.length; i < len; ++i) {
      uInt8Array[i] = this.response[i];
    }
    var byte3 = uInt8Array[4]; // byte at offset 4

    // OR, create a blob until xhr.responseType = 'blob' is in:
    var bb = new WebKitBlobBuilder();
    bb.append(xhr.response);
    var blob = bb.getBlob('image/png');
  }
};

xhr.send();

Comment 28 by ise...@gmail.com, May 5 2011

Thanks for the workaround.
eric: Is there a preferred way to feature sniff for xhr.responseType = 'arraybuffer'; before sending out the request? Is it simply checking that responseType exists in the prototype chain?
eric: Is there a preferred way to feature sniff for xhr.responseType = 'arraybuffer'; before sending out the request? Is it simply checking that responseType exists in the prototype chain?
Yep, this would work fine:

'responseType' in xhr && 'response' in xhr

I think FF4/nightly has a moz prefixed version of responseType
There's a mistake in my comment 27 (http://code.google.com/p/chromium/issues/detail?id=52486#c27).
There's no need for setter loop since you're creating a "view" from the data buffer. So remove:

for (var i = 0, len = uInt8Array.length; i < len; ++i) {
  uInt8Array[i] = this.response[i];
}

It should look like this:

xhr.onload = function(e) {
  if (this.status == 200) {
    var uInt8Array = new Uint8Array(this.response);
    var byte3 = uInt8Array[4]; // byte at offset 4
     ...
  }
};
Labels: -Mstone-13 Mstone-14 MovedFrom13
Moving !type=meta|regression and !releaseblocker to next mstone
Labels: -MovedFrom12 MovedFrom-12
Summary: Implement XHR.responseType='blob'

Comment 36 by k...@google.com, Jul 28 2011

Labels: -Mstone-14 Mstone-15 MovedFrom-14
Punting out non-critical bugs.  Please move back to 14 if you believe this was done in error.

Comment 37 by kareng@google.com, Sep 8 2011

Labels: Mstone-16 MovedFrom15 bulkmove
moving non-essential bugs from 15 to 16. Please feel free to move back if this is an error and your bug is a blocker for 15.

Comment 38 by laforge@google.com, Oct 24 2011

Labels: -Mstone-16 MovedFrom-16 Mstone-17
IE10 PP4 has xhr.responseType = ''blob"

http://ie.microsoft.com/testdrive/HTML5/BlobBuilder/

Comment 40 by k...@google.com, Dec 19 2011

Labels: -Mstone-17 Mstone-18 MovedFrom-17
Moving bugs marked as Assigned but not blockers from M17 to M18.  Please move back if you think this is a blocker, and add the ReleaseBlock-Stable label.  If you're able.
Cc: kinuko@chromium.org
What's the status on this? Seems like it's partially implemented.

Comment 44 by kareng@google.com, Feb 7 2012

Labels: MovedFrom18 Mstone-19
Status: Fixed
Landed: http://trac.webkit.org/changeset/109635
Project Member

Comment 46 by bugdroid1@chromium.org, Oct 13 2012

Labels: Restrict-AddIssueComment-Commit
This issue has been closed for some time. No one will pay attention to new comments.
If you are seeing this bug or have new data, please click New Issue to start a new bug.
Project Member

Comment 47 by bugdroid1@chromium.org, Mar 10 2013

Labels: -Area-WebKit -Mstone-19 M-19 Cr-Content
Project Member

Comment 48 by bugdroid1@chromium.org, Mar 14 2013

Labels: -Restrict-AddIssueComment-Commit Restrict-AddIssueComment-EditIssue
Project Member

Comment 49 by bugdroid1@chromium.org, Apr 6 2013

Labels: -Cr-Content Cr-Blink

Sign in to add a comment