The mysteries of the internet

Today I wanted to learn how to load the contents of a file from my own computer into a web browser. I did a Web search, and discovered lots of forums, tutorials and discussion groups on the topic.

A number of the on-line discussions seemed to devolve into a kind of religious war, with some participants asserting that such a thing was simply impossible, and others saying that accessing a file from disk was sort of morally wrong. Apparently it goes against the spirit of the Web.

One odd thing about such assertions is that they seem to have no relationship to reality. After all, if you’ve ever uploaded to a web site a document you wrote or an image you took (which nearly everyone has done by now), then you have clearly read the contents of a file from your computer into a web browser.

I did find some tutorial sites on the topic, but they were all very long, with gnarly code that ran on for pages. It had seemed like such a simple question, and I was astonished to find the on-line answers to be anything but straightforward.

Eventually I figured out what was going on, by assembling little bits and pieces from different places. When I was all done, the whole thing took just one line of HTML plus four lines of Javascript. For those of you who care, here they are:

      <input id=”input” type=”file”>
      var chooser = document.getElementById(‘input’);
      var reader = new FileReader();
      chooser.addEventListener(‘change’, function() {reader.readAsText(this.files[0]);});
      reader.onload = function() { fileText = this.result; }

So what are all those people out there going on about? I’m starting to suspect there may be something very odd about Web programming culture.

I’m just not quite sure yet what it is.

3 Responses to “The mysteries of the internet”

  1. J. Peterson says:

    This is a great description of a phenomena I’ve been observing for a while. I suspect the cause is the web’s formats and standards evolve slowly and at a low level. This drives people to build their own tools and “standards” to be more productive. But there’s no “winner”, just many factions. Want a UI toolkit? No problem, just choose one: JQueryUI, Bootstrap, YUI, GWT, etc. etc.

    This very different from, say, developing for iOS. There everybody reads Apple’s documentation, uses Apple’s tools and follows Apple’s examples.

    The web’s fragmentation of libraries, styles and “best practices” makes it challenging to develop content creation tools for making web sites. Output that delights one customer is just as likely to irritate another.

  2. Without a doubt. It’s been that way for a while.
    It use to be a big thing with people who coded html by hand vs using software. People are funny…

  3. Jon Kleiser says:

    Thanks a lot! I’va always wanted to do this.

Leave a Reply