Get url for <web-resource> specified in atlassian-plugin.xml using JS

Hello here, I’ve gone through several docs but can’t seem to figure how to specify a correct base url for abd <img /> created using Javascript. After specifying the and building the plugin, I’m not sure how I can dynamically (with JS) create an <img> who’s src points to my plugin assets folder already defined in by a <web-resource>.

I’ve noticed that the path to my JS looks someting like /confluence/s/d41d8cd98f00b204e98009988339323-CDN/en_GB/7901/NOCACHE/2.0.0-SNAPSHOT/_/download/resources/{artifact-id}:{resources-key}/{resource-name}.{ext}, and I can access this in the browser by substituting the{resource-name}.{ext}.

Is there a way to expose such resource path to my plugin.

Hi, I’ve found the way to formulate an URL to the images within the plugin.

/s/2025/1/1.0/_/download/batch/${pluginKey}:${webResourcekey}/${location}/${filename}

e.g. if my atlassian-plugin.xml is

<atlassian-plugin key="com.atlassian.confluence.plugins.search.confluence-search" name="Confluence Search Plugin" plugins-version="2">
   <web-resource key="confluence-search-resources" name="confluence-search Web Resources">
      <resource type="download" name="images/" location="/images" />
      <context>confluence-search</context>
   </web-resource>
</atlassian-plugin>

and I have a file

resources/images/pluginLogo.png

then I can access this file from JS using the following URL

/s/2025/1/1.0/_/download/batch/com.atlassian.confluence.plugins.search.confluence-search:confluence-search-resources/images/pluginLogo.png

assuming the root context is /

Thanks for sharing Huyle.
I was able to solve this by specifying a <resource> for all my media file (it wasn’t part of a <web-resource>. Then I got the server url using SettingsManager
So it looks something like SettingsManager.getGlobalSettings().getBaseUrl()/download/resoursces/{artifactID}.{groupID}/{resource name}. Then I just passed this value to the JS (AJS).

For thouse who trying to do the same

Correct path is:
{BaseUrl}/download/resources/{atlassian.plugin.key}:{web-resource.key}/{location}{path-to-file}

So, given :
BaseUrl=http://localhost:1990
groupId=com.example
artifactId=test-plugin
atlassian.plugin.key={groupId}.{artifactId}=com.example.test-plugin
file in project=src/main/resources/things/mypage.html
so, path-to-file will be just “mypage.html”

and web-resource described as folows:

<web-resource key="stuff" name="My Web Resources">
    <resource type="download" name="things/" location="things/"/>
</web-resource>

resulting link will be:

http://localhost:1990/download/resources/com.example.test-plugin:stuff/things/mypage.html

1 Like