[whatwg] data: URI origin

Ian Hickson ian at hixie.ch
Tue Jun 14 15:19:19 PDT 2011

On Mon, 14 Mar 2011, Luis Marsnao wrote:
> I'm attempting to write a client-side script that processes a user 
> selected file through an input element. Since the input element 
> interface conceals the file: URI, the best solution I can think of is to 
> access the file through the input element's interface, get its data: URI 
> through readAsDataURL in FileAPI's FileReader interface, and process the 
> data: URI. However, I get not-same-origin errors when I try to use this 
> URI. Specifically, this happens when I try to use XMLHttpRequest to 
> retrieve an XML resource with the data URI.

With XHR, yes, that's normal, as I understand it. You can't usefully use 
XHR with data: URLs.

With <iframe>s you should be able to read the content.

> Is there a better way to process files in a client-side script? I 
> considered using blob: URIs, but the support is not yet there.

FileReader is the way you're supposed to do it from a File object.


Since you have a data: URL, you could also just decode the data: URL 
yourself. It contains all the data.

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list