View all attachments in some pages

jasper January 22, 2025

How to view all attachments under one page tree? We require everyone to upload his attachments to his own project page under one page tree. I know the Space Attachment Macro to check the whole attachments in one space. But I just want to see the whole files of one page tree in a space. Does anyone know how to deal with it? Thanks! 

1 answer

1 vote
Humashankar VJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 25, 2025

Hi @jasper 

Confluence does not offer a native macro that can directly list attachments from a specific page tree, as it only supports listing attachments for an entire space.

You can also explore some Marketplace Apps.

Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards

Roma Bubyakin _Wombats Corp_
Contributor
January 25, 2025

Hi @jasper if you need to list them from specific page give a try to my Page Information macro app

Regards, Roma (Wombats Corp)

Like jasper likes this
jasper January 25, 2025

Thanks for your reply! I did find no any native macro to achieve.  

jasper January 25, 2025

@Roma Bubyakin _Wombats Corp_ sorry that I cannot use the confluence cloud for we use data center version. I have no administration to try it. Maybe will be considered in the near future.

Roma Bubyakin _Wombats Corp_
Contributor
February 2, 2025

@jasper it's actually much better, on the DC you can create a custom User Macro that will do whatever you need just from the admin panel.

Here is the template for you.
It is based on the JS and shows attachments as a clickable list.
As input, it uses Page ID or current as default.

## SERVER SYNTAX

## @param ID:title=Page ID|type=int|desc=Page ID to fetch attachments from|default=-1

## Determine the target page ID
#set ($pageID = $paramID)
#if ($pageID == -1)
#set ($pageID = $content.id) ## Default to current page if no ID is provided
#end

## Placeholder for the attachment list (will be populated by JavaScript)
<div id="attachment-list-$pageID">
<aui-spinner size="large"></aui-spinner>
</div>

<script>
(function() {
var pageID = "$pageID";
var container = document.getElementById("attachment-list-" + pageID);
var baseUrl = window.location.origin;

fetch(baseUrl + "/rest/api/content/" + pageID + "/child/attachment")
.then(response => response.json())
.then(data => {
if (data.results && data.results.length > 0) {
var listHtml = "<ul>";
data.results.forEach(attachment => {
var fileName = attachment.title;
var fileUrl = baseUrl + attachment._links.download;
listHtml += `<li><a href="${fileUrl}" target="_blank">${fileName}</a></li>`;
});
listHtml += "</ul>";
container.innerHTML = listHtml;
} else {
container.innerHTML = "<p><strong>No attachments found</strong> for the specified page.</p>";
}
})
.catch(error => {
console.error("Error fetching attachments:", error);
container.innerHTML = "<p style='color:red;'><strong>Error fetching attachments.</strong></p>";
});
})();
</script>

 Preview example with one attachment:
be3a7f00-4268-4943-a768-1670915bf6e5.png

The best part is that you can modify it in any way you wish!

  • User parameter could be not a Page ID, but searchable Confluence page.
  • Formatting could be as a table, for instance.
  • Logic could be rewritten to the "backend" on Apache Velocity instead of the JS.
  • and so on...

P.S. If you need help with that, just let me know

Regards,
Roman

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events