Confluence - Images not rendered through content REST API.

Tanushree Mahajan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2019

This is my curl call:
curl D -X GET -H 'Authorization: Basic *********' -H 'Content-Type: application/json' 'https://mydomain.atlassian.net/wiki/rest/api/content/$pageId?expand=metadata.properties.myprop,bb,body.view,version,container'

 

I get all the text and html in response. But images are not displayed. When the session is going on to Confluence, images are displayed, otherwise not!

Please help!

2 answers

0 votes
Rajpv May 25, 2022

Hello Stephen, Stephen Sifers

I see the below curl cmd working as expected... 

when i post below request - i could the image rendered on the confluence page.

But when i try to render another image - it is overwriting the existing/first image on the confluence page.

 

My question is how do we append the images in the confluence page instead of overwriting... Please suggest. thanks

 

curl --insecure -k --request PUT \
--url 'https://confluence.global.standardchartered.com/rest/api/content/2377271484' \
--user '1628738:<pwd>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
"id":"2377271484",
"type":"page",
"title":"NewPTPage",
"space":{"key":"CC"},
"body":{
"storage":{
"value":"<p>Adding image to page</p><ac:image><ri:attachment ri:filename=\"values.png\" /></ac:image>",
"representation":"storage"
}
},
"version":{"number":14}
}'

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 12, 2019

Hello Tanushree and welcome to the Community!

The info you provided paints a clear picture of what you’re wanting and are accessing. The first thing I see which might explain why your images are not showing is that you’re not viewing the storage format of the Confluence page.

To explain a bit more detail into this, I’ll explain how images are displayed within Confluence. When you have a page within Confluence, you have 2 options to display an image within a page. The two options are a linked image (which exists somewhere else and is referenced as an image) and attached images (which are attached to a page within Confluence and displayed within a Confluence page). Both of these are viewed differently when viewing the Confluence page via the REST API. You are going back to why you’re not able to see the image within your REST API call. From your API call, the endpoint you’re accessing is correct. 

Let's go back to why you’re not able to see the image within your REST API call. From your API call, the endpoint you’re accessing is correct. However, if you want to see an image which is attached to a Confluence page, you will need to view the child/attachment to gain access to the images. The endpoint to access attachments is GET /rest/api/content/{id}/child/attachment. With this endpoint, you would make a call to request any attachments for the parent page which may have an image attached.

I hope this explains why images are not directly displayed via the endpoint you’re requesting along with how images may be stored and displayed within Confluence.

Regards,
Stephen Sifers

Tanushree Mahajan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 12, 2019

I have used this API already. It gives a json response with a _links attribute which has download and webui attributes in it.

I merged the atlassian base url and the download link from response and hit the merged link in browser, it took me to the login page of atlassian.

Which link am I supposed to provide to the image source to display the image or make it downloadable?

Also how we should add images to confluence page? Right now we are just copy pasting the image in the editor. We can change the way so as to get the response in REST API.

Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 18, 2019

Hello Tanushree,

Thank you for replying and providing additional clarification.

If you want to access page attachments externally then, you will have to authenticate to get to the files attached. You would either need to pass through authentication when attempting access or enable anonymous access to the site.

For setting up Confluence anonymous access, please review Setting Up Public Access. This would allow you to make content available without having to authenticate to Confluence. However, this does not apply to all applications as this would let all content to be publically available.

I hope this helps clarify how to access your attachments within Confluence.

Regards,
Stephen Sifers

dinesh korgaokar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 22, 2021

hello @Stephen Sifers can u show example for    to authenticate to get to the files attached.

i am been trying to authenticate image from page not able to do it. using token to authenticate.

Nalin Agrawal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 10, 2021

What I dont understand is why attachements need Anonymous access? What is the security concern? Some user can very well expose sensitive data in text as well, which is freely avaialble via APIs, but for some wierd reason attachments are not.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events