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 = event.target.files;
console.log(files);
}
$('input[type=file]').trigger('change');
console.log(files);
var data = new FormData();
data.append('file', files[0]);
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. Any suggestions?