Hi all,
I’m trying to attach an image to the confluence page but I keep receiving a 403. I am following the steps here Confluence Docs. I’ve given permissions to all users and adding attachments is enabled. Here is my code:
var form = new FormData();
form.append("file", $("#fileInput")[0].files[0]);
var data = {"file": form , "comment":"test attachment", "minorEdit": "true"};
AP.request({
url: "https://my-test.atlassian.net/wiki/rest/api/content/76021794/child/attachment",
type: "POST",
data: data,
contentType: "multipart/form-data",
headers: {
"X-Atlassian-Token": "nocheck",
"Accept": "application/json"
},
success: function (data){
return data;
},
error: function(jqXHR, textStatus, errorThrown){
return deferred.reject(jqXHR.responseText);
}
});
Also trying on postman gives me a 403, current user not permitted to use Confluence. Any help will be appreciated!
The issue was I didn’t have write as a scope in my atlassian-connect. Another issue was I was receiving a 500 for passing in the form instead of the direct file. Thank you so much.
I do have a side question. On server there was the ability to pass in allowDuplicate into the query params. Is this still available on cloud? If not what is the recommended way to handle duplicate filenames?
Hi @JustinArias,
That’s great that you are now able to add attachments. 
Regarding your second question about duplicate attachments, the create attachment resource doesn’t support overwriting attachments (400 error is returned), but the create or update attachment resource does.
If you want to avoid overwriting existing attachments, but guarantee that the attachment is added, then maybe consider a file naming scheme such as adding a timestamp or hash to prevent clashes.
Regards,
Dugald
2 Likes
Dear @JustinArias and @dmorrow,
Would you please help me at this? I have issue when use this code to attach a file:
var fileToUpload = document.getElementById(“testfile”).files[0];
var data = {“file”: fileToUpload , “comment”:“test attachment”, “minorEdit”: “true”};
AP.request({
url: “/rest/api/content/18415730/child/attachment”,
type: “POST”,
data: data,
contentType: “multipart/form-data”,
headers: {
“X-Atlassian-Token”: “nocheck”,
“Accept”: “application/json”
},
success: function (data){
return data;
},
error: function(jqXHR, textStatus, errorThrown){
//return deferred.reject(jqXHR.responseText);
}
});
An the error returns:
I can use curl command to attach successfully. Would you please let me know how to fix this issue?
Thanks!!!
Hi @elitesoftsp,
I’ve created a new topic for this.
Regards,
Dugald