Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Upload attachment using REST API Edited

Hi, feeling a bit desperate here....

I'm trying to create a file upload step in Blueprint wizard and I've spent 3+ days trying to get it to work using jQuery/AJAX and the upload attachment API. See: Upload an attachment

I've had success using curl in my terminal to execute the upload but every iteration I've come up with for an AJAX http request has had an error or issue with it. I've also been successful using jQuery for a similar task (creating a new page). 

Does anyone have a working example of a file upload using jQuery? Alternately, is there another method I might not be aware of? 

If you want to see my code, here's what I have at the moment:


    wizard.on('submit.page1Id', function(e, state) {
		var files;
		$('input[type=file]').on('change', prepareUpload);

		function prepareUpload(event)
		  files =;


		var data = new FormData();
		data.append('file', files[0]);

			type: "POST",
			url: "http://localhost:1990/confluence/rest/api/content/917506/child/attachment",
			contentType:"multipart/form-data; boundary=------------------------021ab64c72420e84",
			async: false,
            cache: false,
			headers: {
				"Authorization": "Basic " + btoa("admin:admin"), "X-Atlassian-Token": "no-check"
			data: JSON.stringify(data),
			success: function (){
				console.log('Attachment saved!'); 
			error : function(xhr, errorText){
				console.log('Error '+ xhr.responseText);

I've tried (and Googled) everything I can think of. It seems so simple yet I can't seem to get anything to work. Any suggestions?

2 answers

1 accepted

1 vote
Answer accepted

Edit: What is your error message, if any.

Try changing the line

data.append('file', files[0]);


data.append('file', files);

As far as i can see, the source maps the "file" into a list:

public RestList<Content> createAttachments(@PathParam("id") ContentId contentId,
                                               @MultipartFormParam("file") List<FilePart> fileParts,
                                               @Nullable @MultipartFormParam("comment") List<FilePart> comments,
                                               @Nullable @MultipartFormParam("minorEdit") List<FilePart> minorEdits) throws ServiceException

Thank you Panos, I appreciate the suggestion. 

I tried changing it to: data.append('file', files);
and receive this error in the console: 
"AbortError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:1990/confluence/rest/api/content/917506/child/attachment'."

To give you a sense of the other things I've tried, so far I've: 

  • Added/removed: "async: false," 
  • Added/removed: "cache: false,"
  • Added/removed: "processData: false,"
  • Changed contentType between "multipart/form-data", "application/json", and "false"
  • Added/removed: "JSON.stringify()" from the data

Everything seems to throw an error of some sort or doesn't throw an error but aborts.

Any suggestions would be much appreciated!

I made it work with:

var files;
$('input[type=file]').on('change', prepareUpload);

function prepareUpload(event)
files =;
var actionData=new FormData();
actionData.append('file', files[0]);
actionData.append('comment', "foobar");
actionData.append('minorEdit', "true");
type: "post",
url: path,
data: actionData,
processData: false,
headers: {
"X-Atlassian-Token": "nocheck"
contentType: false,
cache: false,
success: function (data, status, response) {for (var pair of actionData.entries()) {
console.log(pair[0]+ ', ' + pair[1]); 
error: function(response){console.log(response);}});


THANK YOU!!! You have no idea how much I appreciate this. I spent days (and a few nights) on this without making any progress. 

I had to rework it a bit to work with my instance but it works perfectly. Thank you!

:) I am glad it worked!

Hi Panos,

I was writing this rest call for attachments to be added to a new page when using the blueprint wizard however I can't find a way to specify the new page id (variable) in the rest call. Do you know if there is a way to do this or it is not possible because the page doesn't exist yet?

If it's not possible with the rest call, I'm guessing I would need to write java method/class to handle it using a listener on the BlueprintPageCreateEvent, right? If so, any chance you would be able to give me some direction or help me write something that would accomplish this?

I've gone through the Atlassian tutorials and have the event listener working but I'm hitting a roadblock. 

I found a potential solution described in a comment here:

The concept seems straightforward and makes sense but I can't figure out what's needed in the code because java is new to me. I'm willing to learn and I'm trying my best to get it working but I didn't realize I would need java and my project is due tomorrow. I would really appreciate any help, ideas, or direction!

Hello, please post a new question explaining what you want to do and when the attachment should be attached. I am not very familiar with blueprints myself.

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

<message>org.apache.commons.fileupload.FileUploadE xception: the request was rejected because no multipart boundary was found</message><stack-trace>java.lang.RuntimeExcep tion: 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");

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");



please use a separate thread

Abhinay, that's not the issue I'm having though I posted a comment that should help.  

Panos, I developed some java to try to accomplish what I'm describing however I'm running into a new issue here: PageManager Error when Copying Attachment (

Any help would be much appreciated!

@Panos below script worked for me.


curl -D- -u user1:Password1 -X POST -H "X-Atlassian-Token: no-check" -F "file=@available.sh_orig" ""


However, There's no label upon uploaded, Is there a way to put also a label name on it? Hope for your response...Thanks

According to this you can only add comment. If you want to add label you should do a separate call

Like Christophe Marchewka likes this

I'm having a similar issue but I'm using axios. Can someone please check it out?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

🥓🙅🏻‍♀️ Meet-less May Badge!

Hello Confluence Community!  What if i told you that you could have a healthier life and be 100% meet-less? This month, we're promoting a healthy, balanced work diet with Confluence. (Read m...

605 views 4 26
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you