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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 attachments to confluence via rest api

I am able to create / upload an attachment file to our confluence via rest api call scripts below:

 

curl -L -D- -u username:password -X POST -H "X-Atlassian-Token: no-check;" "file=@<path to file>" https://<hostname>/rest/api/content/{page_id}/child/attachment

 

This script works and I found the attachment icon in the confluence page. However the icon is sooo small next to the header and it is hard to find. Since the page I created is for display report to senior engineers and managers who are usually very busy.

Is there are way to make the attachment in the body of the page so that it is easy to find or is there a way to post image / snapshots directly in the body of the page?

 

Thanks! 

2 answers

1 accepted

0 votes
Answer accepted
DPK J Community Leader Nov 18, 2019

@Zhenye NaWelcome to the community!

First of all very nice question. Now, let jump to the possible solutions that can presumably help you resolve your issue,

Solution 1 - Using HTML Macro and Base64 Encode Image

  • Push image directly into confluence page, using structured format of HTML Macro
< ac:structured-macro ac:name = "html" >
   < ac:plain-text-body > <![CDATA[<div><img height="" width="" src="data&colon;image/png;base64,...." />"</div>]]> </ ac:plain-text-body >
</ ac:structured-macro >

Solution 2 - Displaying attachment from source

Followed the solution from https://community.atlassian.com/t5/Confluence-questions/How-to-edit-the-page-content-using-rest-api/qaq-p/904345

 

got json response via a PUT request

 

here is the body section of response

 

"body": {
"storage": {
"value": "<p>Display attachment in body of the page</p>",
"representation": "storage",
"_expandable": {
"content": "/rest/api/content/98797437"
}
},
"_expandable": {
"editor": "",
"view": "",
"export_view": "",
"styled_view": "",
"anonymous_export_view": ""
}
},

 

But the pdf attachment does not display in the page yet, am I missing something ?

 

I ran

PUT /rest/api/content/<PAGEID>?expand=body.storage

With a Payload of:

{
"type":"page",
"title":"TITLE OF PAGE",
"version":{"number":n},
"body":{
"storage":{
"value":"BODY OF PAGE",
"representation":"storage"
}
}
}

@Zhenye NaI don't think PDF's are displayed inline by default. You can only add link to them.

For PDF Preview, you can try some external plugin from Marketplace, I myself don't use any currently so can't suggest, sorry for that.

Like Zhenye Na likes this

Thanks! at least I know this cannot be done currently. 

Is it possible to display images in the body using rest api? if so, any instructions?

 

Thanks!!!

Hi 

can you guide me, i am struck to upload a image in confluence with rest api. i don't know how to solve this problem.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What do you think is the most *delightful* Confluence feature? Comment for a prize!

- Create your own custom emoji 🔥 - "Shake for Feedback" on mobile 📱 - An endless supply of GIFs via GIPHY 🤩 Is there anything quite as nice as a pleasant surprise? Comment below with what...

402 views 23 8
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