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

Is it possible to display an image via REST API Edited

Jake Adkins Apr 10, 2017

I know it's possible to attach an image to a page using the REST API, but is it possible to actually display that image on the page itself by making some sort of API call or adding some sort of HTML to the page? I tried doing an update with "value":"<img src='/download/attachments/\" + id + \"<myfile>.png' width='967px'></img>" but it wasn't displayed.

Edit: I found this issue: https://jira.atlassian.com/browse/CONFSERVER-40979 Was it ever resolved?

2 answers

1 accepted

1 vote
Answer accepted
Jake Adkins Apr 10, 2017

Here's my workaround using the python requests library:

def imageTag(id, file):
 #Get info about attachment
 modDate = ConfluenceAPI.geta(id, file)
 try:
  modDate = str(modDate)
  index_start = modDate.find("version=")
  index_start = index_start + 27
  index_end = modDate.find("'", index_start)
  index_end = index_end - 7
  modDate = modDate[index_start:index_end]
 except:
  print (modDate)
  exit(2)
 
 return "<p style=\\\"text-align:center;\\\"><span class=\\\"confluence-embedded-file-wrapper\\\"><img class=\\\"confluence-embedded-image\\\" src=\\\"/download/attachments/" + id + "/" + file + "?version=1&amp;modificationDate=" + modDate + "&amp;api=v2\\\" data-image-src=\\\"/download/attachments/" + id + "/" + file + "?version=1&amp;modificationDate=" + modDate + "&amp;api=v2\\\" data-unresolved-comment-count=\\\"0\\\" data-linked-resource-id=\\\"" + id + "\\\" data-linked-resource-version=\\\"1\\\" data-linked-resource-type=\\\"attachment\\\" data-linked-resource-default-alias=\\\"" + file + "\\\" data-base-url=\\\"" + ConfluenceAPI.getURL() + "\\\" data-linked-resource-content-type=\\\"image/png\\\" data-linked-resource-container-id=\\\"" + id + "\\\" data-linked-resource-container-version=\\\"1\\\"></img></span></p>"


Where ConfluenceAPI.geta(id, file) is defined

def geta(id, file):
 
 payload = {'filename' : file}
  
 r = requests.get(
  url + '/rest/api/content/' + id + '/child/attachment',
  params = payload,
  auth=(user, pass_)
 )
 
 return r.json()
rdwyer@metabolon.com Mar 05, 2019

Jake, man, if you use single quotes around your strings, you don't have to escape all the double quotes.   And if you use r"...", you don't have to escape the backslashes.  And someone looking at what you're doing might understand it.

Chris Westcott Mar 28, 2019

This is great - thanks.

 

First example I've seen embedding an image into a page.  I guessed you'd have to upload an attachment, then reference it in the page, but this has confirmed it :)

0 votes
Sam Hall Apr 10, 2017 • edited

Hi Jake - Are you referring to Confluence or JIRA here?

Edit: Oops. Sorry, it is clear now from the link you've given that you are talking about Confluence. I'll move your question to the Confluence section.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

2,440 views 11 28
Read article

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