Skip to content

readAsDataURL should be more precise about the data URL contents #104

Description

@domenic

In particular, it appears all browsers base64-encode the contents; see jsdom/jsdom#2269 for the original report.

Probably it'd be best to give the exact algorithm for creating the string from the contents of the type attribute and the bytes of the Blob.

Activity

  1. annevk commented on Jun 21, 2018

    @annevk
    Member

    See also whatwg/fetch#665 which this would tie into (if someone wants to work on that, feel free, happy to assist).

  2. inexorabletash commented on Jun 21, 2018

    @inexorabletash
    Member

    Re: "creating the string from the contents of the type attribute" - just a note in case someone tackles this. Beware of the gotcha associated with #43 - namely, as the spec is currently written, the value returned by the type attribute's getter and the internal type of the blob (which isn't clearly documented) differ if the type is not a parseable MIME type.

  3. shannonbooth commented on Apr 8, 2026

    @shannonbooth
    Contributor

    Regarding the mime type, WPT tests that an unspecified mime type should be application/octet-stream which all browser implementations have aligned on.

    https://github.com/web-platform-tests/wpt/blob/844e3e5ec7d746c04c8aabb5ab5e8e3732ce732c/FileAPI/reading-data-section/filereader_readAsDataURL.any.js#L42

  4. shannonbooth commented on Apr 8, 2026

    @shannonbooth
    Contributor

    Though, saying that - it's not clear whether the mime type should fall back to that as well for a mime type which is parsable or not.

    Based on the following test, I think the logic is probably just if it is not an empty string in all browsers at least:

    async_test(function(testCase) {
      var blob = new Blob(["TEST"], { type: 'not a mime type' });
      var reader = new FileReader();
    
      reader.onload = this.step_func(function() {
        assert_equals(reader.result,
                      "data:not a mime type;base64,VEVTVA==");
        testCase.done();
      });
      reader.readAsDataURL(blob);
    }, 'readAsDataURL result for Blob with unparsable MIME type');
  5. annevk commented on Apr 9, 2026

    @annevk
    Member

    There's a separate issue on making sure type is always valid. We should really attempt to fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions