DailyJS

HTML5 File API

Introduction

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

firefox html5

HTML5 File API

Posted by Alex R. Young on .
Featured

firefox html5

HTML5 File API

Posted by Alex R. Young on .

Firefox 3.6 has new features from HTML5's File API. This makes it
possible for JavaScript to read the contents of local files. As an
example, that means showing thumbnails prior to uploading files is now
possible.

According to the draft HTML5 File
API
, browsers should provide
the following:

  • A FileList sequence, which represents an array of individually selected files from the underlying system using
  • A Blob interface, which represents raw binary data, and allows access to ranges of bytes
  • A File interface that includes details on file name, type and a URL
  • A FileReader interface, which provides methods to read a file
  • A FileError interface and a FileException exception

There are API docs for FileReader on Mozilla's developer
site
.
Mozilla also has a document called Using files from web
applications

with example code for uploading files. Although they mention generating
thumbnails their example doesn't do any image processing -- it's
expected that an implementor would use CSS to create thumbnails to
display before and during the upload process.

Since the File API is asynchronous, files could be loaded and processed
in the background while the user does other things. This could also be
useful for creating web applications that work offline.