File API

瀏覽次數:46 次
跳到第一則未讀訊息

Remy Sharp

未讀,
2010年6月13日 清晨7:09:472010/6/13
收件者: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

未讀,
2010年6月13日 下午1:24:042010/6/13
收件者: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

未讀,
2010年6月14日 清晨7:18:252010/6/14
收件者: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

未讀,
2010年6月14日 清晨7:45:112010/6/14
收件者: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

未讀,
2010年6月14日 下午4:46:052010/6/14
收件者: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).
回覆所有人
回覆作者
轉寄
0 則新訊息