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

Fetching avatar image from Connect Addon

Salvatore "Sax" Cammarata November 30, 2015

Hi, 

 I am trying to fetch the content of a user avatar image in JIRA (e.g. http://myserver.atlassian.net/jira/secure/useravatar?size=small&avatarId=10346") from a Connect Addon.

If I try to download the content using a not authenticated http request I get a "No 'Access-Control-Allow-Origin' header is present on the requested resource. ".

Is there a way to retrieve the content from client side using some Connect API? 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Stephen Deutsch
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

Too bad, it used to be super easy with the JSON-RPC call, since it returned a base64 encoded version of the avatar for you to use.

0 votes
Robert Massaioli _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 30, 2015

I have a few comments:

  • Your URL looks strange for a Cloud url: it should not have the '/jira' context path. In Cloud the context path of JIRA is nothing, so the url should look like:

    http://myserver.atlassian.net/secure/useravatar?size=small&avatarId=10346
  • The /secure/useravatar url is marked as PRIVATE and thus you should not be using it if you can avoid it. I would recommend using the Get User public api instead. It will return the avatars for the user in the response body.

  • You seem to be communicating from your Atlassian Connect addon directly to the host product. Are you generating a JWT token to make that call?

Is there a way to retrieve the content from client side using some Connect API?

Yes, there is. It is called AP.request and you can see the documentation for it here: https://developer.atlassian.com/static/connect/docs/latest/javascript/module-request.html

Try making a request to the Get User public api using AP.request client side and you should have much more luck.

Stephen Deutsch
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

If you actually take a look at the Get User response, you can see that it only returns links to the avatar images, not the images themselves.

Robert Massaioli _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 1, 2015

Is that an issue for an Atlassian Connect addon? If the connect addon really needs to hold on to the image then it can download the asset at the avatar image url. Otherwise you can just point your img tags in your HTML to that avatar url.

Stephen Deutsch
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 1, 2015

You're probably right, I'm just not 100% sure. Since the Connect Add-on runs on a separate server within an Iframe, I'm not totally sure if JIRA makes that information publicly accessible or not... I would try it if I had time :)

Robert Massaioli _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 2, 2015

JIRA at-least makes that information avaliable to logged in users. :)

Salvatore "Sax" Cammarata December 2, 2015

Hi Robert , Thanks for your help on this issue. Just few observations on your comment: - the "http://myserver.atlassian.net/secure/useravatar?size=small&avatarId=10346"; is exactly what it is returned by the "Get User" public API - as you suggested, in order to fetch the content from the avatar URL you need to make an authenticated request (e.g. using JWT) - the fetching of the image content cannot be done via the AP.request: unfortunately the Connect Javascript API does not allow binary transfer. This solution imply two authenticated GET requests in order to retrieve the content of the avatar. This is why I was wondering for a possible alternative/more efficient solution comparable to the JSON-RPC (that returned a base64 encoded version of the avatar) mentioned by Stephen. In any case, thanks for confirming that the authenticated REST API + authenticated GET binary on the returned avatar URL is the only solution available. PS The 'jira' context path is returned in the avatar URL if you launch a test instance of the JIRA server locally.

Robert Massaioli _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2015

@Salvatore Cammarata why do you need to download the users avatar? What are you trying to accomplish?

Salvatore "Sax" Cammarata December 3, 2015

Hi Robert, Our plugin needs to show the users that are working at the same project (in real time) by showing their avatars

Robert Massaioli _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 6, 2015

@Salvatore Cammarata does it do that inside an Atlassian Connect iFrame window?

Salvatore "Sax" Cammarata December 6, 2015

Yep

TAGS
AUG Leaders

Atlassian Community Events