JIRA 7 programmatically setting project avatar

mgajic November 30, 2015

How can I programmatically update project avatar in JIRA 7, before JIRA 7, i was catching my newly created projects with project hook and using AvatarManager.create(String fileName, String contentType, Project owner, InputStream image, Selection selection) method, and then updating the project with the newly created avatar.

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
mgajic December 4, 2015

Finally I got it to work.

I had to use this approach:

final Avatar newAvatar = AvatarImpl.createCustomAvatar("avatar-name.png", "image/png", project);
final Avatar createdAvatar = this.avatarManager.create(newAvatar, imageStream, null);

Don't know why the other one didn't work.

Volodymyr Krupach
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.
December 4, 2015

Thank you for sharing!

3 votes
mgajic December 2, 2015

Hi Volodymyr,

Thank you for you answer.

I am using the same approach, but I get js error that the resource could not be found (the project avatar icon).

I debugged the code, and everything is being set properly( my image is being properly created as avatar and than being updated to the project).

So I was wondering does anyone else have the same problem?

Volodymyr Krupach
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.
December 2, 2015

Please check the image link for your avatar. Maybe it passes wrong avatar.id. One more: do you see that the avatar file was created in JIRA filesystem. I do not remember exact path but I remember I was able to track it under /target folder when I was coding avatar uploading.

mgajic December 3, 2015

Not sure what you mean by image link, but the id of the created avatar, matches the one sent to updateProject method, and after that method, i retrieve that project, and it has the correct avatar id. Yes there are couple of images generated at : target\jira\home\data\avatars p.s.Sorry for long time to answer but I have a 24h hour post limit.

Volodymyr Krupach
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.
December 3, 2015

Added a new answer to be able to attach the image. Also voted you up so you can post.

2 votes
mgajic December 3, 2015

Here is my image link:

avatarId.png

The avatar id is correct, but of course I am getting 404 link not found page on that URL.

I'll try with debugging the code that creates the image.

0 votes
Volodymyr Krupach
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.
December 3, 2015

Here is image illustrating image link:avatar.png

Make sure that the correct avatarId is passed. If id is fine and you still do not get you image you can try to debug a code that serves the image.

0 votes
Volodymyr Krupach
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.
November 30, 2015

Hi Milan,

What does stop you in JIRA 7?

There still is AvatarManager.create with the parameters you mentioned. and there is ProjectManager.updateProject that has parameter for avatarId.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events