File API

49 views
Skip to first unread message

Remy Sharp

unread,
Jun 13, 2010, 7:09:47 AM6/13/10
to Chromium HTML5
Chrome 6's milestones include the File API - and I know that simple support is in Chrome 5 too - but I wanted to check that support for file.getAsDataURL() will be coming to the dev channel (or is this something I can turn on to play with?).

Cheers,


Remy Sharp
___________________________

Pre-order my HTML5 book: http://introducinghtml5.com

Eric Bidelman

unread,
Jun 13, 2010, 1:24:04 PM6/13/10
to Remy Sharp, Chromium HTML5
Both Chrome dev channel and FF 3.6.3 support the FileReader's readAsDataURL:

var reader = new FileReader();
reader.onload = function(e) {
  //var fileContent = e.target.result;
}
reader.readAsDataURL(file);

file.getAsDataURL() is a deprecated FF API. 

Eric


--
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
Developer Relations - Google
e.bid...@google.com

Remy Sharp

unread,
Jun 14, 2010, 7:18:25 AM6/14/10
to Eric Bidelman, Chromium HTML5
Sorry, you're going to have to excuse my ignorance, but I'm not seeing Chrome's support for the File API working (I'm on Chrome 6 dev channel).

Here's the demo I mocked together, it simply allows you to drop a file from your desktop to the browser and it reads it in: http://rem.im/file-api.html

Is it that the File API has been implemented, but not completely in the dataTransfer object? Again, sorry if I'm misreading this.

Cheers,

Remy Sharp

Paul Kinlan

unread,
Jun 14, 2010, 7:45:11 AM6/14/10
to Remy Sharp, Eric Bidelman, Chromium HTML5
Hi,

The File object is on the data transfer object, but that doesn't expose any methods.  You do it via the FileReader API.  I believe the spec says that the file object only consists of properties such as URI (http://www.w3.org/TR/FileAPI/#dfn-file)

So in your example, like Eric said, you need to do the following

var file = e.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = function(e) {
  // var fileContent = e.target.result;
  // Do some stuff like set img.src.
}
reader.readAsDataURL(file);

P

Jian Li

unread,
Jun 14, 2010, 4:46:05 PM6/14/10
to Remy Sharp, Eric Bidelman, Chromium HTML5
You need to use FileReader interface as defined in the File API spec (http://dev.w3.org/2006/webapi/FileAPI).
Reply all
Reply to author
Forward
0 new messages