I am using "/rest/api/content/22157686/child/attachment" call to upload an attachment to a Confluence space. When I try this in Postman, the file gets uploaded with no problem. I then tried to write JavaScript code to mimic that call. I used REST request. I could not get that to work even though several other of the Confluence API calls do work, including update a page. So I know the JavaScript is working and set up properly for the other API calls. For the create attachment call though, it seemed like the multipart/form-data was not being properly parsed and sent to the server. To simplify, I tried using AJAX instead of REST and copying the exact code from Postman. After some small modifications with headers, the call seems to be hitting the server, but the response is always null. Here is, more or less, the entire code. It is not long or complicated:
var FormData = require('form-data');
var form = new FormData();
form.append('file', 'C:/Users/<userid>/barnum-2.0/swagger.json');
settings = {
'async': true,
'crossDomain': true,
'url': `https://share-staging.<company>.com/rest/api/content/22157686/child/attachment`,
'method': 'POST',
'dataType': 'json',
'headers': {
'X-Atlassian-Token': 'nocheck',
'Cache-Control': 'no-cache',
'Authorization': authorizationData,
'X-Content-Type-Options': 'nosniff',
'Accept': 'application/json; charset=utf-8'
},
'processData': false,
'contentType': false,
'mimeType': 'multipart/form-data',
'multipart': true,
'formData': form
}
ajax(settings, function (response) {
console.log('response :', response)
done();
});