Issues attaching pictures using Confluence REST API

Mariana Aires January 18, 2020

I'm using the REST API to create a program that takes pages stored locally and uploads them into Confluence. I'm having issues if the page contains picture. So far, how I do it is: 1. create an empty page, and get the pageID. Then, make a post request to attach the picture to that page id. And thirdly, I'm updating the page with the layout I want (in xml). The last part fails, if I include the <ac:image> tag, returning a 500 internal error.

<ac:image ac:height="55"><ri:attachment ri:filename="image.png"/></ac:image>

 

That's the tag I'm using to upload the image. The request works without it and changes the page just fine.

 

1 answer

1 accepted

0 votes
Answer accepted
Minh Tran
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 18, 2020

@Mariana Aires You need to upload the "image.png" to the page first before saving it with 

<ac:image ac:height="55"><ri:attachment ri:filename="image.png"/></ac:image>
Mariana Aires January 19, 2020

I upload the picture to the page first, and it uploads it successfully under "attachments", and only then try to insert the image into the page.

Minh Tran
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 19, 2020

@Mariana Aires Can you share the exception in your server log? And what Confluence version have you been using?

Mariana Aires January 19, 2020

Okay after checking the logs and doing some testing, I figured out the problem was I wasnt escaping the quotes correctly in the height and the filename. I was only escaping the quotes (as " -> \") but its also necessary to escape the backslash (so \" -> \\\"), in Java. Thank you a lot for the help and I hope my solution might solve the problem for anyone having the same issue. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events