title: Sending file to server from a HTML input file
body: <p>I have a web page where I upload file from an input type file HTML element.
  Then I need to send that file by Url with Ajax to a Java server to a REST web service where it will be processed.</p>
  
  <p>I tried FileReader().readAsDataURL function in javascript, file is encoded in base64 then sent to server by url. But when I try to decode it in Java, it fails.</p>
  
  <p>How can I achieve this ?</p>
  
  <p>My code client-side :</p>
  
  <pre><code>var file = document.getElementById('add_attach').files[0];
  var filename = document.getElementById('add_attach').value;
  
  if (file) {
      var reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = function(e) {
          var name = encodeURIComponent(filename);
          var file_content = e.target.result;
           //Ajax request to server with sending file_content
      };
  }
  </code></pre>
  
  <p>My code server-side :</p>
  
  <pre><code>file_content = file_content.substring(file_content.indexOf("base64"));
  file_content = file_content.replace("base64,", "");
  byte[] decodedBytes = Base64.getDecoder().decode(file_content);
  </code></pre>
  
  <p>The errror I get :</p>
  
  <pre><code>java.lang.IllegalArgumentException: Illegal base64 character 20
  </code></pre>