title: Sending files and text with AJAX + multipart form data + UTF-8 encoding
body: <p>I've been all day trying to make the client send AJAX requests with UTF-8 encoding in FormData() objects. I'm using Sping MVC on the server side, but that doesn't apply in this case, since:</p>
  
  <ol>
  <li><p>I can POST to the server non-multipart requests, and I can capture the request and see:</p>
  
  <pre><code>Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  </code></pre>
  
  <p>and I also can see the characters encoded OK (á, é, í, ó, ú).</p></li>
  <li><p>If I POST using AJAX + file upload + FormData, using the following code:</p>
  
  <pre><code>var data = new FormData();
  data.append('body', jq("#sp_body").val());
  data.append('signature', jq("#sp_signature").val());
  data.append('subject', jq("#sp_subject").val());
  data.append('email', jq("#sp_email").val());
  data.append("file", jq("#sp_file")[0].files[0]);
  jq.ajax({
      url: contextPath + "/jobs/" + job + "/sendmail",
      data: data,
      cache: false,
      dataType: 'text',
      processData: false,
      contentType: false,
      mimeType: "multipart/form-data",
      type: 'POST',
      success: function(result){
          data = jq.parseJSON(result);
          if (data["statusCode"] == "success") {
              jq("#save_status").html("Email sent!").show().delay(5000).fadeOut(200);
          } else {
              jq("#save_status").html(data["errors"]).show().delay(5000).fadeOut(200);
          }
      },
      error: function (xhr, ajaxOptions, thrownError) {
          alert(xhr.status);
          alert(thrownError);
      }
  });
  </code></pre>
  
  <p>Then I capture the request and I see:</p>
  
  <pre><code>Content-Type: multipart/form-data; boundary=---------------------------279972256522979
  </code></pre>
  
  <p>But no UTF-8 in the header, and the non-latin characters are garbled.</p></li>
  </ol>
  
  <p>The question is, how can I POST using FormData (since I want to POST strings and a file at the same time), having UTF-8 encoding set?</p>
  
  <p>I've read <a href="https://stackoverflow.com/questions/546365/utf-8-text-is-garbled-when-form-is-posted-as-multipart-form-data">UTF-8 text is garbled when form is posted as multipart/form-data</a> but that didn't help me.</p>