Stand with Ukraine 🇺🇦

Image from Attachments — Confluence Cloud Macro

visualsconfluence-contentmedia

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.

Try for free

User Parameters

Attachment

Full attachment name e.g. menubar.png Night Image.jpg

123

Height

Height in px of the image

123

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>