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

How to insert an image into a Confluence blueprint template

Andrew Lensen February 9, 2014

We are developing a blueprint plugin and need to include a logo inside the page template as part of this, which ideally will be bundled with the plugin.

How can we access this image within our blueprint? After trying a few things, the closest I've got is formatting the xml within a Java context provider like such:

blueprintContext.put("logoURL", "<ac:image><ri:url ri:value=\"" + logoUrl + "\"/></ac:image>");

and then referring to the variable in the XML:

<at:var at:name="logoURL" at:rawxhtml="true"/>

but this cuts out the URL value attribute in the ri:url tag altogether and displays "Broken Image". The image itself can be referenced fine -- if I manually edit the page after it has been constructed and add the url parameter the image will show.

This is the XML being inserted:

<ac:image><ri:url ri:value="/confluence/s/en_GB-1988229788/4731/NOCACHE1/1.0/_/download/resources/my.plugin.confluence.blueprints:logoResource/logo.png"/></ac:image>

which gives the following exception:

[INFO] [talledLocalContainer] com.atlassian.confluence.content.render.xhtml.XhtmlException: com.atlassian.confluence.content.render.xhtml.XhtmlException: Missing required attribute: {http://atlassian.com/resource/identifier}value

[INFO] [talledLocalContainer]at com.atlassian.confluence.content.render.xhtml.storage.resource.identifiers.StorageResourceIdentifierUnmarshaller.unmarshal(StorageResourceIdentifierUnmarshaller.java:73)

[INFO] [talledLocalContainer]at com.atlassian.confluence.content.render.xhtml.storage.resource.identifiers.StorageResourceIdentifierUnmarshaller.unmarshal(StorageResourceIdentifierUnmarshaller.java:48)

and then the page source shows:

<ac:image>
<ri:url/>
</ac:image>

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Ed Letifov [TechTime - New Zealand]
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.
February 9, 2014

Apparently the value in the ri:value of ri:url has to be absolute i.e. "[protocol:]//host[:port]/confluence/..." e.g:

https://myhost/confluence/s/en_GB-1988229788/4731/NOCACHE1/1.0/_/download/resources/my.plugin.confluence.blueprints:logoResource/logo.png

I can only guess that "relative URL" doesn't get properly consumed by image macro (though seems to be perfectly acceptable in the Insert Image dialog) and then when you view source - doesn't get displayed.

Andrew Lensen February 10, 2014

Thanks Ed, that seemed to fix it. A pity the macro isn't as smart as the dialog!

Cris Kinross July 6, 2017

How would this work if the macro was purchased from the Marketplace? The base url would change each time. Has anyone found a way to add an image to a blueprint that is available in the Marketplace?

 

Thanks so much!

1 vote
Steve Gerstner [bridgingIT]
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.
February 9, 2014

You can use a base 64 encoded image directly in the template. Take a look here: http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html

0 votes
Jose Crespo May 2, 2016

@Andrew Lensen

As a matter of example, could you please write down which value-path  did you set for your logoUrl variable?

Thx a lot!

Ed Letifov [TechTime - New Zealand]
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.
May 2, 2016

As per initial question post:

/confluence/s/en_GB-1988229788/4731/NOCACHE1/1.0/_/download/resources/my.plugin.confluence.blueprints:logoResource/logo.png

Jose Crespo May 2, 2016

@Ed Letifov, thanks a lot!

 

What I am trying to figure out is how to find out such a path in my Confluence SDK. 

I have something like this:

031-131-1577539:1990/confluence/s/de_DE/5527/NOCACHE1/

Then added the trailing continuation with something like that:
  /images/logo/confluence-logo.png

 

But the result in the confluence blueprint is a broken image.  What  am I doing wrong?. I appreciate very much some advice.

 

Ed Letifov [TechTime - New Zealand]
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.
May 2, 2016

As per the solution the path must be absolute i.e. contain protocol, host, port (if different from the default for the protocol), application context and the path to the image.

I think you need to use one of the methods in WebResourceManager probably getStaticPluginResource

Please note in Andrew's case he was trying to refer to an image within a plugin i.e. as far as the page is "concerned" something that is external to the page. If that was an attachment to the question it would have been different and wouldn't have this problem.

Jose Crespo May 3, 2016

Thanks a lot, that is really a great help!.

Yes I am working on a blueprint plugin, therefore your solution suits me.

Let me please show you what I found out according to your clues and how to carry on next.


NOTE: WebResourceManagerImpl:: getStaticPluginResource is deprecated. Then instead:

1.-  from the upgraded package com.atlassian.plugin.webresource I would say that one should use the new class SinglePluginResource (is an image considered as a resource here?) and the method public String getUrl () after creating the instance with the constructor public SinglePluginResource (String resourceName, String moduleCompleteKey, boolean cached) . Ref: https://developer.atlassian.com/static/javadoc/plugins/2.6/reference/com/atlassian/plugin/webresource/SinglePluginResource.html


2.-  Regarding the constructor where it should be located the resource ,  i.e. "logo.png" , in the src/main/java or in the src/main/resources ? .
The moduleCompleteKey = 'com.prueba.blueprint.simpleform' is in fact in my src/main/java.

 Secondly, I guess that  the String resourceName  should be just the name of the resource = 'logo.png' located in such a module:''com.prueba.blueprint.simpleform'', shouldnt be ?


Thanks very much for your efforts in advance!



 

Dallas Devam
Contributor
July 24, 2019

Why is there no simple "Insert Image" in the Global Template editor?

Like # people like this
TAGS
AUG Leaders

Atlassian Community Events