The Ashes

Technology, Science and other news
August 12, 2009

W3C publish first working draft of File API

Posted by : admin
Filed under : General

The W3C has published a working draft for the File API which gives us a much improved <input type=”file”> and programmatic ability to work with file uploads and the like.

There are actually a few pieces to this work, which does a good job interfacing with other standards too:

This specification provides an API
for representing file objects in web applications, as well as programmatically selecting them and accessing their data. This includes:

  • A FileList interface, which represents an array of individually selected files from the underlying system.
    The user interface for selection can be invoked via <input type="file">, i.e. when the
    input

    element [HTML5] is in the File Upload state, or through the FileDialog interface.

  • A FileData interface, which provides asynchronous data accessors for file data via callback methods.
  • A File interface, which includes readonly informational attributes about a file such as its name and its mediatype.
  • A FileError interface, which defines the error codes used by this specification.

The API to get access to selected files is trivial (document.getElementById("myFileInput").files.length etc) and then you can get the file data itself in various forms (data: URL, text, binary, Base64, new filedata:// URL).

An example usage of the filedata URL:

PLAIN TEXT
JAVASCRIPT:

  1.  
  2.  
  3. // Sample code in JavaScript
  4. // Obtain fileList from <input type="file"/> using DOM
  5.  
  6. var file = fileList.files.item(0);
  7. if (file)
  8. {
  9.  // … Make asynchronous call
  10.      
  11.  file.getAsURL(handleURL);
  12. }
  13. function handleURL(url, error)
  14. {
  15.  if(url)
  16.  {
  17.    var img = new Image();
  18.    img.src = url;
  19.    
  20.    // Other stuff…
  21.    
  22.  }
  23.  else
  24.  {
  25.    // error conditions
  26.  }
  27. }
  28.  

Fun to see this all come together. The editor is a fellow Mozilla-n Arun Ranganathan … an all round good chap 🙂

Some have talked about alternative solutions such as using XHR to do the work, or DOM events to allow built-in progress events. The working group is listening, what would you like to see?

Tags :

No Comments

(required)
(will not be published) (required)
(opitional)

cciash.com EN ES IT DE PT CZ FR RU
September 2018
M T W T F S S
« Sep    
 12
3456789
10111213141516
17181920212223
24252627282930

Pages

Categories

Resources

There are many online poker site where you can play but at poker.hk you can play the poker games with all the knowledge you need related to the game with the poker school available in both the English and Chinese language.

Super Casino

Now you can bet on any sports and any sporting events from all the comfort from your home. Bet770 allows you to bet on any events and match with in just 3 clicks. They also offers great odds on football betting for every premier and champions league match. Get £50 free in bets when you register.

Bingo770, offering best online bingo games with £7.70 free no deposit Bonus!