title: Convert PDF files to decimal array before sending
body: <p>I have a form that I need to send its contents using json and curl to an API.
  It all works fine, until I get to the files.</p>
  <p>The form receives from the user between 1 to 4 PDF files, which I need to send as a decimal array.</p>
  <p>I don't have much experience with this kind of tasks but I've looked around and the best I could get is converting the file in JS to Base64 which is converted to Base16 and sent to the server side using ajax to be converted to decimal and sent.</p>
  <p>It held as long as I used small files of no more than few hundred KB, but when tried larger files - it seems that the size of the package to be sent is like 4 times the size of the original files... I guess there's something to do with the &quot;over conversion&quot; which adds to the file size in each conversion.</p>
  <p>This is my JS for converting the file from the input field to comma separated Base16 string</p>
  <pre><code>$('.file-field').on('change', function(e) {
    var input_id = $(this).attr('id')
    var file = e.target.files[0];
    var filename = file.name;
    var filetype = file.type;
    var filesize = file.size;
    var data = {
        &quot;filename&quot;: filename,
        &quot;filetype&quot;: filetype,
        &quot;filesize&quot;: filesize
    };
    var reader = new FileReader();
    reader.onload = function (e) {
        data.file_base64 = e.target.result.split(/,/)[1];
        var file_base16 = base64ToBase16(data.file_base64);
        var file_base16CS = file_base16.replace(/.{2}/g, '$&amp;,');
        $(&quot;#&quot;+input_id+&quot;_array&quot;).val(file_base16CS).attr({
            &quot;filename&quot;: data.filename,
            &quot;filetype&quot;: data.filetype,
            &quot;filesize&quot;: data.filesize,
        });
  
    };
    reader.readAsDataURL(file)
  </code></pre>
  <p>And this is on the PHP:</p>
  <pre><code>$thefile = $dataArray[&quot;thefile&quot;];
  if($thefile['file'] != 0) {
      $file_hex_array = explode(&quot;,&quot;, $thefile['file']);
      $file_dec_array = array();
      foreach($file_hex_array as $file_hex) {
         $file_dec_array[] = hexdec($file_hex);
      }
  }
  </code></pre>
  <p>Is there a way to make the process more simple and handle larger files without making them huge?</p>