Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Attachment Parameter in confluence plugin issue

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

9 votes
Answer accepted
Joe Clark Atlassian Team Nov 04, 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!

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

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

Thanks a lot! This has been very helpful!

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.

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>

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you