HTML5 File API Example

Learning By Doing - Here we try to provide some sample codes and links to external resources. There is a lot of HTML5 materials.

Image File Picker

Pick a image / file and upload to server. This sample using File API, FileReader
  1. Trigger a system file picker
  2. Insert the image back to the DOM for review
  3. Send to server

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Zetakey HTML5 Webkit Browser - Sample Codes</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <p>This sample use HTML5 file API, review and upload</p>

    <form action="upload_file.php" method="post"
      <label for="files">Filename:</label>
      <input type="file" id="files" name="files[]" multiple />
      <input type="submit" name="submit" value="Submit">

    <output id="list"></output>

      function handleFileSelect(evt) {
        var files =;
        // FileList object

        // Loop through the FileList and render image files as thumbnails.
        for (var i = 0, f; f = files[i]; i++) {

          // Only process image files.
          if (!f.type.match('image.*')) {

          var reader = new FileReader();

          // Closure to capture the file information.
          reader.onload = (function(theFile) {
            return function(e) {
              // Render thumbnail.
              var span = document.createElement('span');
              span.innerHTML = ['<img class="thumb" src="',, '" title="', escape(, '"/>'].join('');
              document.getElementById('list').insertBefore(span, null);

          // Read in the image file as a data URL.

      document.getElementById('files').addEventListener('change', handleFileSelect, false);