Stand with Ukraine 🇺🇦

Attachments in the Space — Confluence Cloud Macro

confluence-contentmedia

This macro lists all attachments in the current Confluence space, displaying the filename, filetype, creation date, creator, and file size. It retrieves the data using a REST API call and formats it in a sortable AUI table.

Try for free

User Parameters

This macro comes without configurable user parameters.

Template

#set( $query = "type=attachment and space='${space.key}'" )
#set( $expand = "extensions,version" )
#set( $url = "/wiki/rest/api/content/search?limit=250&expand=${expand}&cql=${query}")

#set( $attachments = $ConfluenceManager.get($url).results )

<table class="aui aui-table-sortable">
  <thead>
    <tr>
      <th></th>
      <th> Filename   </th>
      <th> Filetype   </th>
      <th> Created On </th>
      <th> Created By </th>
      <th> Size       </th>
    </tr>
  </thead>
  <tbody>

  #foreach ( $att in $attachments )
    <tr>
      <td><a href="${baseUrl}${att._links.download}"><span class="aui-icon aui-icon-small aui-iconfont-download"></span></a></td>
      <td>
        <a href="${baseUrl}${att._links.webui}">$att.title</a>
      </td>
      <td> $att.extensions.mediaType </td>
      <td> $att.version.friendlyWhen </td>
      <td>
        <a href="${baseUrl}/people/${att.version.by.accountId}"><span class="aui-lozenge">${att.version.by.publicName}</span></a>
      </td>
      #set ( $kb = $att.extensions.fileSize / 1024 )
      <td> $kb kB </td>
    </tr>
  #end
  </tbody>
</table>