How to identify owner of user avatar files in <JiraHome>/data/avatars directory


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

    

Summary

Avatars are custom pictures uploaded to Jira for a specific entity (eg. user, project, issue types, etc). Users can upload custom avatars as per the following documentation: Managing your user profile - Changing your avatar. This article explains how an admin can identify owners of user avatar files in the <JiraHome>/data/avatars directory, and also how to safely remove them.

Environment

Any version of Jira

Solution

The /data/avatars directory store several different types of avatars. Below lists some of the types of avatars it stores

  • Issue type avatars
  • Project avatars
  • User avatars

Each single avatar file uploaded to Jira will have multiple files of different sizes within this directory. Here is an example of all the files stored in the directory for a single user avatar uploaded in Jira

10647_large@3x_profilePicturejrvtg.png
10647_medium_profilePicturejrvtg.png
10647_profilePicturejrvtg.png
10647_small@3x_profilePicturejrvtg.png
10647_small_profilePicturejrvtg.png
10647_xlarge_profilePicturejrvtg.png
10647_xsmall_profilePicturejrvtg.png
10647_xxlarge@2x_profilePicturejrvtg.png
10647_xxlarge@3x_profilePicturejrvtg.png
10647_xxlarge_profilePicturejrvtg.png
10647_xxxlarge@2x_profilePicturejrvtg.png
10647_xxxlarge@3x_profilePicturejrvtg.png
10647_xxxlarge_profilePicturejrvtg.png


Apart from being stored in this directory, records of these avatars are also stored in the avatar table in the database. Below is the record in the database which corresponds to the files above

  id   |                 filename                 | contenttype | avatartype |     owner     | systemavatar
-------+------------------------------------------+-------------+------------+---------------+--------------
 10647 | profilePicturejrvtg.png                  | image/png   | user       | JIRAUSER10000 |            0

As you can see, the ID of the avatar in the database is prepended to the name of the files in the directory.


If the avatars directory has grown to a very large size, it's most likely due to excessive user avatars. If you attempt to manually remove the files or the DB records individually, you will be left with orphaned records/files which may cause unwanted behaviours within Jira. Instead, you can perform the following.


The below database queries will help you identify users with the highest number of uploaded custom avatars

-- Users with highest number of avatars
SELECT DISTINCT(A.OWNER), COUNT(A.OWNER), AU.LOWER_USER_NAME, CU.LOWER_EMAIL_ADDRESS
FROM AVATAR A
LEFT JOIN APP_USER AU ON A.OWNER = AU.USER_KEY
LEFT JOIN CWD_USER CU ON AU.LOWER_USER_NAME = CU.LOWER_USER_NAME
WHERE SYSTEMAVATAR = 0 AND AVATARTYPE = 'user'
GROUP BY A.AVATARTYPE, A.OWNER, AU.LOWER_USER_NAME, CU.LOWER_EMAIL_ADDRESS
ORDER BY COUNT(A.OWNER) DESC;

-- Deleted users with highest number of avatars
SELECT DISTINCT(A.OWNER), COUNT(A.OWNER), AU.LOWER_USER_NAME
FROM AVATAR A
LEFT JOIN APP_USER AU ON A.OWNER = AU.USER_KEY
WHERE SYSTEMAVATAR = 0AND AVATARTYPE = 'user'
	AND AU.LOWER_USER_NAME not in (SELECT LOWER_USER_NAME FROM CWD_USER)
GROUP BY A.AVATARTYPE, A.OWNER, AU.LOWER_USER_NAME
ORDER BY COUNT(A.OWNER) DESC;

(info) Queries written for PostgreSQL. You may have to re-write them for your specific DB.

With this information, you can inform the top users to remove some of the avatars to free up some disk space. If you have admin permissions in Jira, you can also remove these avatars on your own by running the below cURL command


curl -u <username>:<password> -X DELETE "<baseURL>/rest/api/latest/user/avatar/<id>"
  • Replace <username> and <password> with credentials of your admin user. Replace <baseURL> with the URL of your instance
  • Replace <id> with the ID of the avatar you want to delete

For example:

curl -u admin:password -X DELETE "http://localhost:8080/jira/rest/api/latest/user/avatar/10607"


Running the above curl command will safely remove the avatar from the directory and its corresponding DB record. 

You can use any alternative API client to perform the request and achieve the same results (eg. https://www.postman.com/).




Last modified on Dec 7, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.