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

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

Scriptrunner - provide own images to JIRA (over web resource f.e.) Edited

Deleted user May 03, 2018

Dear community!

 

What I am trying to do, is including an image over a script fragment. (On the issue overview page).

Using Script Fragments, I can create a new div element with an image in it.

However, I am only able to access the images in

JIRA_INSTALL_DIR/images

 

I am trying to find a way to provide images from JIRA_HOME however.

Has anyone an idea how to achieve that?

 

EDIT:

I am using a web resource (javascript) to add a picture to a specific place, f.e. in the issue view above the issue description, see code below.

(function ($) {
    $(function () {
        /**
         * Binding is required for link such as
         * http://localhost:8080/jira/projects/JRA/issues/JRA-4?filter=allopenissues
         */
        JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (event, $context, reason) {
            if (reason === JIRA.CONTENT_ADDED_REASON.pageLoad || reason === JIRA.CONTENT_ADDED_REASON.panelRefreshed) {
                addLogo();
            }
        });

        addLogo();
    });

    function addLogo() {
        var projectKey = "PROJECTKEY";
        var issue = JIRA.Issue.getIssueKey();
        if (typeof (issue) !== "undefined") {
            var currentProject = issue.substr(0, issue.indexOf('-'));
            if (currentProject == projectKey) {
                $("div.issue-body-content div.issue-main-column").prepend("<img id='theImg' src='/LOGO.png'/>");
            }
        }
    }
})(AJS.$);

 

Thank you very much!

Best regards,

Alex

2 answers

Hi Aliaksanr,

How are you currently accessing the images in the JIRA_INSTALL_DIR/images directory ?

I might be mistaken in thinking that a simple solution may be to retrieve the image you want using the Groovy method: 

return new File(filePath)

 If I have misunderstood the requirement please let me know and offer some more detail.

Thanks

Johnson Howard (Adaptavist)

Deleted user May 07, 2018

Hi!

My question was not well explained, I have updated it.

In general I do not provide any images from the install directory, as those images are "provided" by Jira itself and can be easily accessed over the web, e.g.:

jira_url/issue/images/icons/priorities/major.svg

this picture is located in

/images/icons/priorities/major.svg in the install dir.

I want to include my own pictures in a similar way, but from the HOME directory, as you shouldn't put any custom files in the install dir.

 

Thanks!

Alex

Hi Alex,

I think I understand now. Your web resource will only find images that are placed in the JIRA_INSTALL_DIR/images, and won't work if you attempt to put the images in the HOME directory? 

When you attempt to access them from the HOME directory do you put a fully qualified path? or just the file name, as you have in your js example.

Thanks

Johnson Howard (Adaptavist)

Radek Janata Community Leader Jun 16, 2021

@JohnsonHoward, we can't really use ScriptRunner's web resources to add our own custom resources? When talking about resources I mean my custom images/icons. I.e. I want to use SR's web resources to load only only CSS/JS, but also PNGs.

At this time, I have to store my custom images under JIRA_INSTALL_DIR/atlassian-jira/images and load them via <img scr="/images/my_custom_image.png">.

However, this location is not good in case of future Jira upgrades therefore I'd like to have all my custom images stored somewhere under JIRA_HOME/scripts/resources where I have all my customizations.

Thanks.

As a workaround you can Base64 encode your logo image and put the code directly in javascript.

There are numerous image encoders/decoders online, one of them http://freeonlinetools24.com/base64-image

The code you put in the javascript looks like this:

<img src='data&colon;image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO....' />

Suggest an answer

Log in or Sign up to answer
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