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

is it possible to display image in confluence page through rest api

noor basha December 19, 2019

Hi All,

 

I am able to upload image through rest api. but i dont know how to display that image. please guide me.

 

Thanks in advance

1 answer

3 votes
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 19, 2019

@noor basha  I have already sent you a reply on your previous question.

Here is recap of that,

Displaying attachment on confluence page is another part of story and you will need to fire separate APIs for this.

You need to put something like this in your page body using API,

<ac:image>
  <ri:attachment ri:filename="atlassian_logo.gif" />
</ac:image>

Here is an working API example, in first API I'm adding image `sample.png` as attachment and later in second API call I'm displaying that in page using Confluence Structure format in body.

 

curl -D- -u '<USERNAME>:<PASSWORD>' \
-X POST \
-H 'X-Atlassian-Token: nocheck' \
-F 'file=@"./sample.png"' \
'<CONFLUENCE_BASE_URL>/rest/api/content/<PAGE_ID>/child/attachment'

curl --request PUT \
--url '<CONFLUNCE_BASE_URL>/rest/api/content/<PAGE_ID>' \
--user '<USERNAME>:<PASSWORD>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
"id":"<PAGE_ID>",
"type":"page",
"title":"Sample Page",
"space":{"key":"<SPACE_KEY_OF_PAGE>"},
"body":{
"storage":{
"value":"<p>Adding image to page</p><ac:image><ri:attachment ri:filename=\"sample.png\" /></ac:image>",
"representation":"storage"
}
},
"version":{"number":<NEXT_VERSION_NUMBER>}
}'

noorbasha December 22, 2019

thanks alot sir. it worked, but curl is not working fine i tried with different approach.To display or update i used storage format then i am able to upload or modify any data in the confluence page. 

thanks alot for you help and replay

Kelly Maurice March 27, 2024

Hi noorbasha - can you explain what you mean by using "storage format"? I am having same problems and can't make the code above work.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events