0

I'm trying to read a file with the HTML5 FileReader API. This works fine in Firefox 5.0 but no event is fired in Chromium 12.0.742.112

<html>
  <head>
    <script type="text/javascript">
      function handle(evt) {
      var reader = new FileReader();
      var file = evt.files[0];
      console.log("handling: " + file.name);
      reader.onloadstart = function(e) { console.log("loadstart"); }
      reader.onload = function(e) { console.log("onload"); console.log(e.target.result);  };
      reader.readAsText(file);
      }
    </script>
  </head>
  <body>
    <input type="file" id="input" onchange="handle(this)">
  </body>
</html>

Also the code given in this question Chrome FileReader is not working any more.

My grasp of HTML is rather crude and I cannot see what is wrong with those samples. Is this simply a Chromium bug or is Firefox non-conforming?

I can annotate the sample with ECMAScript5 passages, if this helps and makes things more clear.

Community
  • 1
  • 1
pmr
  • 58,701
  • 10
  • 113
  • 156

1 Answers1

2

The answer is written in the very page that you linked.

If you are on chrome, this code has to be running on a server (localhost or on a site). It won't work with a local file.

Your code logged all 3 messages when I ran it.

shu
  • 46
  • 1
  • 6