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

confluence macro with images

Marco Baldelli July 22, 2014

hi all,
i'm writing a confluence plugin with a simple macro that shows some images, but i can't find a way to display them.

under the atlassian-plugin.xml the declaration for images folder is

<resource type="download" name="images/" location="images/" />

in my macro i use three different urls

<img src="$req.contextPath/download/resource/my.plugin.key/images/image.png" /><br />
<img src="$baseUrl/download/resource/my.plugin.key/image.png" /><br />
<img src="/download/resource/my.plugin.key/image.png" /><br />

but none of them will show me my image... i tried to put it in a <web-resource> tag too (and then, adding ":resources" after the plugin key), but i didn't get anything from that.. .this is driving me crazy!

one friend of mine said that on his app he has an url like this one

href="/confluence/s/it_IT/3278/363/1.0.0-SNAPSHOT/_/download/resources/another.plugin.key:my.resource.key/my-css.css"

so he told that my urls will never work... but how is that even possibile? and if it's true, how i can build that kind of url?

believe me, i read every single thread and i tried (almost, i guess!) everything, but i'm not being able to show an image on my macro: do you have some kind of suggestions?


thanks in advance,
marco

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Yagnesh Bhat
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.
July 22, 2014

Hi Marco,

Try this :

1) Create a folder called images under src/main/resources and put all your images there. Make sure your plugin knows where to find these images by creating a proper web resource for it in the atlassian-plugin.xml

2) Put all your html in a velocity file with extension .vm , under a directory /src/main/resources/vm

3) Try making your macro render the content from a vm :

public String execute(Map&lt;String, String&gt; parameters, String body,
			ConversionContext context) throws MacroExecutionException {

Map&lt;String, Object&gt; contextMap = MacroUtils.defaultVelocityContext();
...
...

return VelocityUtils.getRenderedTemplate("vm/urvmfilename.vm", contextMap);
}

2 votes
Marco Baldelli July 23, 2014

it worked! i also changed my plugin key, which was a variable from maven pom.xml and i made it a plain string...

thanks!

0 votes
Husain November 23, 2017

Hi,

 

I have added a image in my macro. This image is not showing in user mode after admin login its showing. when I'm coping the image resource and past in direct url then its asking for admin login. Please help.

 

/dowlaod/thumbnails/3344443/image-name.png

 

this is my root

0 votes
Marco Baldelli July 22, 2014

hello yagnesh, thanks for your reply.
the macro works just fine, my problem is only with the resources. the only difference in my code was that i had this

VelocityContext contextMap = new VelocityContext(MacroUtils.defaultVelocityContext());

i changed it with your code but it didn't work. at the same time, i also put my <resource> tag under <web-resource>

&lt;!-- add our web resources  --&gt;
    &lt;web-resource key="resources" name="Analytics Web Resources"&gt;
        &lt;dependency&gt;com.atlassian.auiplugin:ajs&lt;/dependency&gt;
        &lt;context&gt;atl.general&lt;/context&gt;
        &lt;!-- whole folder --&gt;
        &lt;resource type="download" name="images/" location="images/"&gt;
            &lt;property key="content-type" value="image/png"/&gt;
        &lt;/resource&gt;
    &lt;/web-resource&gt;

then i added ":resources" next to my plugin key in the url, but nothing...

what's the difference between using <resource> under <web-resource> or under the <atlassian-plugin> tag?

and then, is there a way to "explore" all deployed resources under confluence or, at least, do some kind of debug during the plugin installation? just to check if my images are deployed: i'm starting to think that there is a problem in that phase because my code seems to be ok!

p.s.: i just checked and the plugin-logo image (declared under <plugin-info>) is shown correctly, so i guess it's not a deploying problem...

Yagnesh Bhat
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.
July 22, 2014

Do the following changes to your code :

1) Make location="/images" (You have made it as "images/") . Try this first.

2) I am not sure if you need the <property> element - I have not used it in my projects so far.

These are some concerns I see in your code rightaway, so lets try changing these first.

Like Cedric.SILVESTRI likes this

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