title: Match a curl request to NancyFx service from browser js
body: <p>I've got a microservice (in NancyFx) that works as expected for the following <a href="https://curl.haxx.se" rel="nofollow">cURL</a> command:</p>
  
  <pre><code>curl --verbose   --form file=@"C:\test\image.png"  http://localhost:8080/file/upload
  </code></pre>
  
  <p>The file shows up inside Nancy as expected at:</p>
  
  <pre><code>context.Request.Files[0]  //The file bytes are here, yeah!!
  </code></pre>
  
  <p>Now I've got to get my web-client to send a selected file to the same service, in the same way.</p>
  
  <p>TLDR; You can skip my failure examples below if you'd like</p>
  
  <p>I've tried several versions of the following with no success:</p>
  
  <pre><code>    var uploadForm = new FormData();  
      // Add the file to the request.
      uploadForm.append("file", file, name);
      var xhr = new XMLHttpRequest();
      xhr.open('POST', 'http://localhost:8080/file/upload', true);
      xhr.onload = function() {
          if (xhr.status === 200)
              alert('File ' + name + 'Upload successfully!!!');
          else errorFn("Upload Failure on file " + name);
      };
  
      //Send the data
      xhr.send(uploadForm);
  </code></pre>
  
  <p>and several versions of the following, also with no success:</p>
  
  <pre><code>    var postConfig = {
          url: 'http://localhost:8080/file/upload',
          data: uploadForm,
          processData: false, //tries without this as well
          type: "POST",
          dataType: "application/x-www-form-urlencoded; charset=UTF-8",
          cache: false,
          success: successFn,
          error: errorFn
      }
      $.ajax(postConfig);
  </code></pre>
  
  <p>I've tried the above with </p>
  
  <ol>
  <li>file = direct reference to $('MyFileSelectorControl').files[0]</li>
  <li><p>file being set with the following code:</p>
  
  <pre><code>var reader = new FileReader();
  reader.onload = function (result) {
      var fileContent = new Uint8Array(result.target.result);
      var encContent = new SP.Base64EncodedByteArray();
      for (var b = 0; b &lt; fileContent.length; b++) {
          encContent.append(fileContent[b]);
      }
      &lt;Set file = encContent and send AJAZ as above&gt;
  };
  reader.readAsArrayBuffer(fileInput);
  </code></pre>
  
  <ol start="3">
  <li>Setting file = to fileContent  above (IOW, after it has been through the reader, but not encoded.)</li>
  </ol></li>
  </ol>
  
  <p>How do I submit this file from javascript (jQuery or standard) so that it works like it does from cURL?</p>