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

Issues attaching pictures using Confluence REST API

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 Jan 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>

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 Jan 19, 2020

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

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
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

3,138 views 4 6
Join discussion

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