# Upload attachment using REST API

**URL:** <https://community.developer.atlassian.com/t/upload-attachment-using-rest-api/2085>\
**Category:** Confluence Development\
**Tags:** rest-api\
**Created:** [April 6, 2017, 1:33am UTC](https://community.developer.atlassian.com/t/upload-attachment-using-rest-api/2085 "2017-04-06T01:33:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blake.manosh](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@blake.manosh](https://community.developer.atlassian.com/u/blake.manosh)\
**Post date:** [April 6, 2017, 1:33am UTC](https://community.developer.atlassian.com/t/upload-attachment-using-rest-api/2085/1 "2017-04-06T01:33:32Z")

</div>

Hi, feeling a bit desperate here…

I’m trying to create a file upload step in Blueprint wizard and I’ve spent 4+ days trying to get it to work using jQuery/AJAX and the upload attachment API.

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:

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

		function prepareUpload(event)
		{
		  files = event.target.files;
		  console.log(files);
		}		
		$('input[type=file]').trigger('change');

		console.log(files);

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

		$.ajax
		  ({
			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.

The error I’m seeing at the moment is: “AbortError: Failed to execute ‘send’ on ‘XMLHttpRequest’: Failed to load ‘[http://localhost:1990/confluence/rest/api/content/917506/child/attachment](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!

---

<div class="post-metadata">

**Author:** ![blake.manosh](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@blake.manosh](https://community.developer.atlassian.com/u/blake.manosh)\
**Post date:** [April 6, 2017, 7:06am UTC](https://community.developer.atlassian.com/t/upload-attachment-using-rest-api/2085/2 "2017-04-06T07:06:03Z")

</div>

For anyone who needs it, this was solved thanks to Panos Karampis here: [https://community.atlassian.com/t5/Confluence-questions/Upload-attachment-using-REST-API/qaq-p/458998/comment-id/77680#M77680](https://community.atlassian.com/t5/Confluence-questions/Upload-attachment-using-REST-API/qaq-p/458998/comment-id/77680#M77680)
