Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Attachment Parameter in confluence plugin issue

Aviram Gabay
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.
October 27, 2012

Hi,

I am trying to build a confluence plugin, and one of my macro's requires the user to upload an image.

I've tried using your

<parameter name="secondImg" type="attachment" required="true"/>

xml under the "parameters" tag in the "atlassian-plugin.xml" file.

When I try to use it I get an empty select box with no options to search\choose attachments.

I know this was an issue before but according to my understanding it was solved.

I am using Confluence V4.3.1

Thanks!

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

11 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 4, 2012

OK, there's an easy way to do this and a hard way to do this. Unfortunately, just setting the parameter type to "attachment" doesn't do anything - you still need to add some JavaScript into your plugin to 'activate' it.

The easy way is pretty straight-forward, but doesn't provide a lot of configuration or flexibility. This is a wrapper around the more complex configuration option:

1) Edit your atlassian-plugin.xml and define your macro's parameter as follows:

&lt;parameters&gt;
  &lt;parameter name="page" type="confluence-content"/&gt;
  &lt;parameter name="name" type="attachment" required="true"/&gt;
&lt;/parameters&gt;

Note:

- You must have a "page" parameter.

- The attachment parameter must be called "name".

2) Add a JavaScript file to your plugin. The contents of this file should be as follows:

(function($) {
 
  var macroName = "my-macro"; 
  var attachmentFileTypes = ["txt", "rtf", "doc"];

  AJS.MacroBrowser.activateSmartFieldsAttachmentsOnPage(macroName, attachmentFileTypes);
})(AJS.$);

Note:

- macroName is the name of your macro.

- attachmentFileTypes is the file extension of the attachments that you want to appear in the attachments parameter.

3) Add this JavaScript file to your plugin as a web-resource. The web-resource requires a context of "macro-browser" in order to be picked up and served in the correct location. Your web-resource declaration should look like this:

&lt;web-resource name="macro-resources" key="macro-resources"&gt;
    &lt;resource type="download" name="examplemacro.js" location="scripts/examplemacro.js"/&gt;
    &lt;dependency&gt;confluence.editor.actions:editor-macro-browser&lt;/dependency&gt;
    &lt;context&gt;macro-browser&lt;/context&gt;
&lt;/web-resource&gt;

Note:

- example.js is the name of the JavaScript file you created in 2).

This is the easiest way you can get it working, but as you can see, you are restricted in the name of the attachment parameter (it must be 'name') and you must also have a 'page' parameter on the macro.

If this isn't suitable for you, you'll need to interact with the Macro Browser's JavaScript API directly to set up the parameter the way you want it. It's a bit too complex to try and describe here, but if you have access to the Confluence source code (highly recommended for any serious Confluence plugin development) you should look for the macro-browser-smartfields.js file in the Confluence core webapp project.

Hope this helps!

Adrian Moerchen
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.
August 8, 2015

Is this still valid in 2015? I've the same problem, but need two fields for selecting attachments.

0 votes
fwoon April 23, 2019

I'm facing the same issue like George in Confluence 6.12.3 using SDK 6.2.6

All my old plugins works perfectly fine able to list the attachments in the dropdown but when i tried creating a new plugin, with all the above confluence-core-macro-fields.js to filter out and this in the atlassian-plugin.xml, it doesn't work now:

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


<parameter name="name" type="attachment" required="false">
<option key="showKeyInPlaceholder" value="false" />
<option key="showValueInPlaceholder" value="true" />
</parameter>

0 votes
George Lewe (Lewe) September 13, 2017

This answer (the "easy" solution) does not seem to be valid anymore.

Using SDK 6.2.15 and Confluence 5.10.2.

As soon as I include the suggested Javascript, the page Editor won't load anymore.

0 votes
Aviram Gabay
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.
November 4, 2012

Thanks a lot! This has been very helpful!

0 votes
Aviram Gabay
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.
October 28, 2012

I've updated to Confluence V4.3.2
Issue still continues.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events