title: Converting base64 image to multipart/form-data and sending with jQuery
body: <p>I have a base64 encoded jpg in javascript which I would like to post to a server which is expecting multipart/form-data.</p>
  
  <p>Specifically, to the pivotal tracker API, which has an example curl call like so: </p>
  
  <pre><code>curl -H "X-TrackerToken: TOKEN" -X POST -F Filedata=@/path/to/file \
  http://www.pivotaltracker.com/services/v3/projects/PROJECT_ID/stories/STORY_ID/attachments
  </code></pre>
  
  <p>I have basic XML only calls to their API working fine, using .ajax like so:</p>
  
  <pre><code>$.ajax({
    url: 'http://www.pivotaltracker.com/services/v3/projects/158325/stories',
    type: 'POST',
    contentType: 'application/xml',
    dataType: 'xml',
    beforeSend: function(xhr) {
      xhr.setRequestHeader("X-TrackerToken", "&lt;KEY&gt;")
    },
    data: '&lt;story&gt;&lt;story_type&gt;feature&lt;/story_type&gt;&lt;name&gt;Fire torpedoes&lt;/name&gt;&lt;/story&gt;',
    success: function() { alert('PUT completed'); }
  });
  </code></pre>
  
  <p>but I am stumped on how to take my base64 encoded jpg and send it as if I had uploaded a file in a form.</p>
  
  <p>Any ideas?</p>