title: How do I send a user uploaded CSV file to my Rails backend with AJAX?
body: <p>I am running a Rails/React web app and have a file input field for users to upload CSV files. I would like to send this CSV file to my backend, parse through it and use the info to create a new batch of users.</p>
  
  <p>I have my input field</p>
  
  <pre><code>&lt;div&gt;
   &lt;label htmlFor="add-doc"&gt;Bulk Add&lt;/label&gt;
   &lt;input style={{display: 'none'}} onChange={this.uploadCSV} id="add-doc" name='csv-file' type="file"/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And my onChange function. I have tried a bunch of different things, mostly I think it comes down to how I am passing the file off, it probably is in the wrong format? I dont know</p>
  
  <pre><code>uploadCSV(evt) {
    evt.preventDefault();
    let file = evt.target.files[0]
    let formData = new FormData();
    formData.append('file', file);
    $.ajax({
      url: '/api/v1/client/employees',
      type: 'POST',
      dataType: 'json',
      data: formData,
      contentType: false,
      processData: false
     });
    }
  </code></pre>