Downloading attachments from Jira Data Center fails with an "Unable to retrieve attachments" error

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

Symptoms

Users receive an "Unable to retrieve attachments" message when trying to download attachments even though all the files exist on the filesystem.

Diagnosis

Attachments can go missing either from encoding issues prior to the upgrade or from the migration process after the upgrade.

Cause

JIRA versions 4.2 and earlier were used to store the file attachments with the name format "Internal ID + name of the file" as shown below:

1 <JIRA_HOME>/attachments/<PROJECT>/<ISSUE_ID>/<ID>_name_of_the_file

This change was done as storing attachments with "name" causes text encoding issues that can result in JIRA being unable to find the attachments. As a result in the later versions of JIRA the attachment structure was changed to use the purely numerical ID in the file name as shown below:

1 <JIRA_HOME>/attachments/<PROJECT>/<ISSUE_ID>/<ID>

From version 7 to the latest version (9.1) the file path for storing attachments received an update:

Attachments are stored in the following directory: $JIRA_Home/data/jira/data/attachments/PROJECT_KEY/x0000/ISSUE_KEY/ID

where the subdirectory x0000 is created and numbered according to the number of issues on the JIRA instance. It uses the following pattern:

Directory name

10000

20000

30000

Issues

1-10,000

10,001-20,000

20,001-30,000

Solution

Workaround

  1. Make a backup of the attachments directory.

    ⚠️ It is very important to do the above step as the script renames/deletes files.

  2. If you are on a Windows server, ensure that a recent distribution of Perl is installed and is added to the PATH.

  3. Copy the following code block into a file and save it as Perl script

    renameattachments.pl

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 use strict; use File::Find; use File::Copy; fatal ("Please pass the attachment directory as a command line argument") if(scalar(@ARGV) != 1); find(\&process, ($ARGV[0])); sub process { return if(m/^\.\$/ || m/^\.\.\$/); if(m/_thumb_/) { info("Removing [$_]"); unlink($_); return; } my $originalfile = $_; my $file = $originalfile; $file =~ s/\s/_/g; my @parts = split(/_/, $file); my $final = $parts[0]; return if ($originalfile eq $final); info("Moving [$originalfile] to [$final]"); &move ("$originalfile","$final") or info("Unable to rename file $originalfile"); } sub info { my $msg = shift; print("$msg\n"); } sub fatal{ info(@_); exit(2); }

  4. Run the below commands:

    1 perl renameattachments.pl /path/to/attachments_directory

The script performs the following actions:

  1. Replaces spaces in the file names with underscores.

  2. Removes all files that contain the _thumb_ substring.

  3. Renames the files to match JIRA 7+'s new numerical-ID-only format.

Updated on April 14, 2025

Still need help?

The Atlassian Community is here for you.