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?
Community moderators have prevented the ability to post new answers.
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.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JIRA at-least makes that information avaliable to logged in users. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Salvatore Cammarata why do you need to download the users avatar? What are you trying to accomplish?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robert, Our plugin needs to show the users that are working at the same project (in real time) by showing their avatars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Salvatore Cammarata does it do that inside an Atlassian Connect iFrame window?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.