Confluence plugin macro attachment field empty

Hi all,
I am working on a new Confluence plugin. It offers page macros. In one of them I need an attachment field, the typical list box. The documentation says to add a parameter in your atlassian-plugin.xml file:

I did it like this:

<xhtml-macro name=...>
      <parameter name="File" type="attachment"/>

The code creates the field but when I open it there are no attachments listed. The listbox is empty.
There are attachments on that page. So that’s not the problem.

I am using the Atlassian SDK 6.2.15 which installs Confluence 5.10.7.

The same mimic works well for type=“spacekey” and type=“username”, only not for the attachment type.

Any idea what that could be? Do I have to import a special library in my Java class maybe?

Best regards,

In my experience, I have found that macro parameters are ignored if they are not all lower-case letters without any special characters. Try switching from ‘File’ to ‘file’

Take a look at this:

Hi Panos,
good idea. I ran into that “spelling” issue before. Unfortunately, in this case it did not make a difference. The listbox is still empty.
Best regards,

Hi David,
I didn’t find that thread before. It sounds very promising. Unfortunately, it breaks more than it fixes. After applying the suggested solution, the page editor does not load anymore or shows an empty page. Problem is the suggested Javascript as far as I can tell.
Considering that the thread is from 2012 I assume it does not applt o modern Confluence anymore.
Best regards,

I figured this out by browsing through several other questions/answerd about the same subject. I tested this in Confluence 6.3.4.

Add an extra web-resource in your atlassian-plugin.xml:

<web-resource key="macro-browser-smart-fields" name="Macro Browser Smart Fields">
   <resource type="download" name="confluence-core-macro-fields.js" location="js/confluence-core-macro-fields.js" />

Create the extra Javascript file
Place the file into the location you specified above. Add the following code:

(function($) {
   AJS.MacroBrowser.activateSmartFieldsAttachmentsOnPage("mymacro", ["gif", "jpg", "png"]);

Make sure you change the macro name to yours and list the file types you want to offer.

Marco parameters
In your macro block, add the following parameters:

<parameter name="page" type="confluence-content" hidden="true"/>
<parameter name="name" type="attachment"/>

You need the confluence-content parameter named “page”. But you can hide it.
Your attachment parameter must be named “name”. You can give it a different label in your properties file.

The above solution worked for me. The listbox contains the specified attachments. The value accessible in the Java class is the file name only though. No page ID or path.

1 Like
  1. Make sure your java file is parked under macros/.java

  2. Make sure it is also specified in your atlassian-plugin.xml

<xhtml-macro key=’’ name="" class=“com.ilm.plugins.macros.”

Also read up on :