Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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 file in confluence by AJAX

Hi,

I have the next code:

AP.context.getToken(function (token) {
var actionData = new FormData();
actionData.append('file', files[0]);
actionData.append('comment', "foobar");
actionData.append('minorEdit', "true");
actionData.append('atl_token', token);

AP.request({
type: 'PUT',
method: 'PUT',
headers: {
"X-Atlassian-Token": "nocheck",
'Accept': 'application/json'
},
data: actionData,
experimental: true,
cache: false,
contentType: 'multipart/form-data',
url: "/rest/api/content/" + PageId +
"/child/attachment",
success: function (data, status, response) {

console.log("SUCCESS", data, status, response);
},
error: function (response) {
console.log(response);
}
});

});

It is returning me 

{
"statusCode":400,
"data":{
"authorized":false,
"valid":true,
"errors":[],
"successful":false
},
"message":"com.atlassian.confluence.api.service.exceptions.BadRequestException: At least one attachment file must be included."
}

But I debug require module and found next - if content-type is "multipart/form-data", then they use data as object and convert it to formData.

Ok I send as object: 

AP.context.getToken(function (token) {
var actionData = {
comment: "check",
file: files[0],
minorEdit: true,
atl_token: token
};

AP.request({
type: 'PUT',
method: 'PUT',
headers: {
"X-Atlassian-Token": "nocheck",
'Accept': 'application/json'
},
data: actionData,
experimental: true,
cache: false,
contentType: 'multipart/form-data',
url: "/rest/api/content/" + PageId +
"/child/attachment",
success: function (data, status, response) {

console.log("SUCCESS", data, status, response);
},
error: function (response) {
console.log(response);
}
});

});

I have got: net::ERR_ACCESS_DENIED and 4 strange (2 before and 2 after): 

[Simple-XDM] Failed to validate origin: https://<>.atlassian.net

 

But in atlassian-connect.json

"scopes": [
"READ",
"WRITE",
"DELETE",
"SPACE_ADMIN",
"ADMIN",
"ACT_AS_USER"
],

I try to resolve that issue 2 days and I don't know how resolve it...

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

241 views 2 5
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