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.
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
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>Recommended Macros
Display page edit and view restrictions in Confluence to get essential permission details, including users, groups, and inherited access.
Shows all attachments from the current space in a table view
Generate a list of labels from all spaces leading to corresponding content pages, organized in alphabetical order.
An overview of all pages within one space which contains the title, the version, and the last updated date
Display the top comments from a selected Confluence page or the current page by default.
Perform customized searches based on labels, content types, and other parameters.
Create dropdown menus in Confluence Cloud with predefined sets of options, multiselect features, and permission gates
Compare unique and common groups between two users