title: Javascript read file without using input
body: <p>I have this code and for a file to be converted into base64 I have to click on Choose file and then select it. I want to hardcode the file name so it is converted to base64 on page load.</p>
  
  <p>JavaScript:</p>
  
  <pre><code>var handleFileSelect = function(evt) {
    var files = evt.target.files;
    var file = files[0];
  
    if (files &amp;&amp; file) {
      var reader = new FileReader();
  
      reader.onload = function(readerEvt) {
        var binaryString = readerEvt.target.result;
        document.getElementById("base64textarea").value = btoa(binaryString);
      };
  
      reader.readAsBinaryString(file);
    }
  
    if (window.File &amp;&amp; window.FileReader
        &amp;&amp; window.FileList &amp;&amp; window.Blob) {
      document.getElementById('filePicker')
          .addEventListener('change', handleFileSelect, false);
    } else {
      alert('The File APIs are not fully supported in this browser.');
    }
  };
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div&gt;
    &lt;div&gt;
      &lt;label for="filePicker"&gt;Choose or drag a file:&lt;/label&gt;&lt;br/&gt;
      &lt;input type="file" id="filePicker"&gt;
    &lt;/div&gt;
    &lt;/br&gt;
    &lt;div&gt;
      &lt;h1&gt;Base64 encoded version&lt;/h1&gt;
      &lt;textarea id="base64textarea"
          placeholder="Base64 will appear here"
          cols="50" rows="15"&gt;
      &lt;/textarea&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>EDIT: Thank you for your answers, they were really helpful.</p>