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.
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).
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>