How to solve this no multipart boundary was found while trying to send attachment via rest call ?

I am getting following error while sending attachment to created issue on JIRA. 


<message>org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</message><stack-trace>java.lang.RuntimeException: org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

I am making an ajax call to send this attachment as multipart-data. 

var blob = canvasImageDataUrl
var fd = new FormData();
fd.append("file", blob,"ss_"+issueKeyid+".png");

$.ajax({
url: "https://"+jiraUrl+"/rest/api/2/issue/"+issueKeyid+"/attachments",
type: 'POST', 
data: fd,
processData: false,
beforeSend: function (xhr) {
xhr.setRequestHeader ("X-Atlassian-Token", "no-check");
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("charset", "UTF-8");
},
success: function(data) {
alert("issue created");

},
error:function(data){
console.log(data);
},
complete:function(xhr,status){
console.log(xhr);
}
});



 

1 answer

Try eliminating this: 

xhr.setRequestHeader("Content-Type", "multipart/form-data");

And add this:

contentType: false,

 

Also, you will need to add a comment and minorEdit to your file data otherwise it won't work. So add this before the ajax request:

fd.append('comment', "foo");
fd.append('minorEdit', "true");

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

419 views 7 5
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you