I have a base64 encoded jpg in javascript which I would like to post to a server which is expecting multipart/form-data.
Specifically, to the pivotal tracker API, which has an example curl call like so:
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
I have basic XML only calls to their API working fine, using .ajax like so:
$.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", "<KEY>")
},
data: '<story><story_type>feature</story_type><name>Fire torpedoes</name></story>',
success: function() { alert('PUT completed'); }
});
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.
Any ideas?
See Question&Answers more detail:os