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

Deleted user May 3, 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

0 votes
dragan ciganovic May 30, 2018

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....' />
0 votes
JohnsonHoward
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 4, 2018

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 7, 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

JohnsonHoward
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 9, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events