Chromium FileAPI and readAs... functions.

51 views
Skip to first unread message

John Chavarria

unread,
Dec 10, 2011, 4:26:19 AM12/10/11
to Chromium HTML5
Hey there,

I am running into troubles getting a simple piece of code to work on
recent implementations of Chromium. I developed this a few month ago
and used to work, not getting back on it seems to fail with Chrome ~13-
>15. More surprisingly, this is still working on Firefox!

What I am trying to do is pretty simple, load a file (through d&d or
form) into a FileReader and read its content as binary string (This is
later used for sending the content into a hand-crafted HTTP request).

Here is the piece of code:

var file = files[0];
var reader = new FileReader();

reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) {
var data = evt.target.result;
console.log(data);
}
};

reader.readAsBinaryString(file);

The result is that evt.target.result is an empty string. In Firefox I
have my nice binary string logged in the console.

Please not that it has the same exact behavior while using:
- reader.onload instead of onloadend
- readAsText() or readAsDataURL() instead of readAsBinaryString()
- reading part of the file using blob.webkitSlice()

Here is the link to a test file showing this bug: http://psi.sh/fileReaderTest.html
(Just drag and drop a file to the red square and look the console, you
can test on Firefox and Chrome to see the difference).

I am pretty stuck here, and couldn't find anything helpful around,
except subjects here where folks had bugs with the FileAPI onload
function being called only the first time, which is not my case since
it's always fired but has no results.

I hope you'll be able to help! Thanks a lot.

Cheers,
- John Chavarria.

Eric Bidelman

unread,
Dec 10, 2011, 1:22:45 PM12/10/11
to John Chavarria, Chromium HTML5
Hi John, I'm not seeing the same in Chrome 17 (dev) on OSX. Can you provide
more details on your setup, version, what type of file, etc.?

- John Chavarria.

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




--
Eric Bidelman | Senior Developer Programs Engineer | e.bid...@google.com 

John Chavarria

unread,
Dec 10, 2011, 1:43:14 PM12/10/11
to Chromium HTML5
I've just noticed something, something actually weird...

The link I gave you guys with the test file I made (http://psi.sh/
fileReaderTest.html) is actually working, and getting me my
binaryString result. But the exact same file is not working on my
local machine... How is that possible? Is there some sort of
security / sandbox that could do that?

That's super weird to me, if someone got an idea :-)

Thanks!
John Chavarria.

Eric Bidelman

unread,
Dec 10, 2011, 2:23:19 PM12/10/11
to John Chavarria, Chromium HTML5
Sounds like you're running the page from file:///. You need to run from a web server
for FileReader to work and not given origin errors.

There's a few flags you can turn on for testing, but I don't recommend using them while
browsing the web:

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

John Chavarria

unread,
Dec 11, 2011, 8:45:58 AM12/11/11
to Chromium HTML5
Thanks for your help, I indeed arrived to the same conclusion.

The "problem" is, this is part of a project wich embarks Chromium to
run apps on the desktop, so we could definitely desactivate the flags
but we need to think of security issues, and reasons for Chromium to
have desactivate this for the file:// protocol, to see if this applies
to our project.

Otherwise I need to find another solution to get the binary content of
a file :-)

Thanks Eric!

On Dec 10, 8:23 pm, Eric Bidelman <ericbidel...@chromium.org> wrote:
> Sounds like you're running the page from file:///. You need to run from a
> web server
> for FileReader to work and not given origin errors.
>
> There's a few flags you can turn on for testing, but I don't recommend
> using them while
> browsing the web:http://www.html5rocks.com/en/tutorials/file/filesystem/#toc-support
>
> On Sat, Dec 10, 2011 at 10:43 AM, John Chavarria

> <chavarria.j...@gmail.com>wrote:

> > To post to this group, send email to chromium-ht...@chromium.org.


> > To unsubscribe from this group, send email to

> > chromium-html5+unsubscr...@chromium.org.


> > For more options, visit this group at
> >http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.
>
> --

> Eric Bidelman | Senior Developer Programs Engineer | e.bidel...@google.com

John Chavarria

unread,
Dec 11, 2011, 11:45:26 AM12/11/11
to Chromium HTML5
By the way, I am interested to know the security reasons that pushed
Chromium to implement this security. Are you guys aware of this?

Thanks a lot!

Cheers,
- John Chavarira

PhistucK

unread,
May 15, 2012, 1:27:06 PM5/15/12
to John Chavarria, Chromium HTML5
It gives malicious local pages free privileged access to files and then they can transmit the contents of such files, however private/important they may be.

PhistucK



To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
Reply all
Reply to author
Forward
0 new messages