Image from Attachments — Confluence Cloud Macro
This user macro displays an image from Confluence attachments using a filename reference. It supports optional height and width settings and validates allowed formats (PNG, JPG, GIF). If the file exists, it renders the image via <ac:image> with its latest download link, keeping visuals updated. It shows warnings if the file is missing or invalid. Ideal for shared assets like logos or UI screenshots—update once, reflect everywhere automatically.
Template
## Check for incompitable filetype
#set ( $name = $parameters["searchName"] )
#if(!$StringUtils.endsWithAny($name.toLowerCase(), ".png", ".jpg", "jpeg", ".gif" ))
<div style="background-color: #fef7c8; padding: 10px; border-radius: 3px;">
<div style="display: inline-block; width: 95%;">
<div style="margin: 1px 0 5px 0;">
<ac:emoticon ac:name="warning" ac:width="30px" /> Image [$name] must be PNG, JPG, or GIF format. Update the Attachment parameter
</div>
</div>
</div>
#stop
#end
## Make the search
#set ( $results = $ConfluenceManager.get("/wiki/api/v2/attachments?limit=1&sort=-modified-date&status=current&filename=$name").results)
## Show a warning if nothing found
#if(!$results)
<div style="background-color: #fef7c8; padding: 10px; border-radius: 3px;">
<div style="display: inline-block; width: 95%;">
<div style="margin: 1px 0 5px 0;">
<ac:emoticon ac:name="warning" ac:width="30px" /> No [$name] attachments has been found (Hint: <i>search is case-sensitive</i>)
</div>
</div>
</div>
#stop
#end
## Add an image in Storage Format
#set ( $url = "${baseUrl}$results[0].downloadLink" )
<ac:image
ac:alt="$name"
ac:title="$name"
ac:height="$parameters['height']"
ac:width="$parameters['width']">
<ri:url ri:value="$url"/>
</ac:image>User Parameters
Attachment
Full attachment name e.g. menubar.png Night Image.jpg
Height
Height in px of the image
Width
Width in px of the image
You May Also Like
Shows all attachments from the current space in a table view
Display page edit and view restrictions in Confluence to get essential permission details, including users, groups, and inherited access.
Display the top comments from a selected Confluence page or the current page by default.
Macro that will show a "Delete me" message only for editors (in the Page Edit mode)
Display Jira issue comments in a table
Perform text searches within pages, blog posts, and attachments.
This macro allows user to retrieve all pages from current space despite limitation of 250 pages per request
An overview of all pages within one space which contains the title, the version, and the last updated date
Show an expandable page tree for a selected parent page (defaults to the current page)
Read and display the fixed version of Confluence pages by checking page or ancestor labels