How to resolve missing attachments in Confluence

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

When viewing or attempting to download attachments, you may receive a "Page not found" error. Additionally, you may receive the following error in the logs:

No AttachmentData object was returned when it was expected for attachment: Attachment: fileName v.1 (123456789)

In many cases, the attachment itself is still on disk - and simply needs to be relocated to the location that Confluence is expecting it to be in. 

Diagnosis - does this apply to you?

If your attachments are still somewhere in your attachment directory, this wiki will be able to help you resolve the broken attachments.  To see if your attachments exist in your attachment directory, search the folder directory for an example attachment id of a broken attachment.  For example, if your attachment has an ID of 123456789, search your confluence home directory for a folder with this name. If you get a result, it means your attachment is on disk. On a unix like system you could do this with a command like find <confluence-attachment-dir> | grep 123456789

If you're using database based attachment storage...

You should refer to the section labelled "Solution - Database Based Attachment Storage" 

If searching for the attachment ID on disk produces no results...

You should not proceed with this document, and instead restore your missing attachments directory from a backup. You may still need to recover missing attachments after restoring the files to disk.

Solution - For file system based attachment storage, and Confluence 3.0 and higher

tip/resting Created with Sketch.

We've got a brand new script for fixing up missing attachments that still exist on disk!

You'll need to download the Missing Attachments Script first. It's a Python script, and you'll need to ensure that Python 2.7 is installed on your server. You can also run the script from a local machine - you simply need to ensure that you can access the attachments directory from wherever you're running the script and be sure to also ensure that the user running this script is the same user account in whom had been used to run your Confluence instance.

Before you begin, ensure you have a full backup of your attachments directory. You should test your recovery on a test server before applying it to production.

First, you'll need to generate the list of attachments to be found. For most case, the following queries will be sufficient:

For Confluence 3.0 to 5.7Confluence 5.7 and above
SELECT s.spaceid, c.contentid, a.attachmentid
FROM attachments a
JOIN content c ON c.contentid = a.pageid
JOIN spaces s ON s.spaceid = c.spaceid
AND c.prevver IS NULL
AND c.spaceid IS NOT NULL
SELECT spaceid, pageid, contentid
FROM content
WHERE contenttype = 'ATTACHMENT'
AND prevver IS NULL
AND spaceid IS NOT NULL

See the README.md file for more customised queries. Once you have the results, follow the steps below:

  1. Using your database tools, export the results of this query as a tab separated file. Ensure that your file does not include the header names.
  2. Save the file as Attachments.txt in the same directory as FindMissingAttachments.py
  3. Shutdown Confluence
  4. Run python FindMissingAttachments.py and follow the prompts
  5. Startup Confluence
  6. Please perform a full content indexing to update the index cache for the attachment file name.

Solution - For database based attachment storage

Please note that as of Confluence 5.6, attachment storage in the database is deprecated. Newer instances cannot swap to database attachment storage. If you are running database attachment storage, we recommend you migrate to file system storage.

There is no tool available to generate a report for missing attachments. However, if you find that you have attachments missing you can restore the attachment to the attachmentdata table from a recent SQL backup.

If you do not have a Confluence backup from which you can restore an attachment, you can delete the attachment's record from the database:

To delete the attachment if using database storage,

Run these SQL commands:

For Confluence 5.7 and newer
DELETE FROM CONTENTPROPERTIES WHERE CONTENTID IN (SELECT CONTENTID FROM CONTENT WHERE CONTENTTYPE = 'ATTACHMENT' and TITLE LIKE '%<ATTACHMENT_NAME>%');
DELETE FROM CONTENT WHERE CONTENTTYPE = 'ATTACHMENT' AND TITLE LIKE '%<ATTACHMENT_NAME>%';
For Confluence 5.6.x and older
DELETE FROM attachmentdata WHERE attachmentid IN (SELECT attachmentid FROM ATTACHMENTS WHERE TITLE LIKE '%<ATTACHMENT_NAME>%' );
DELETE FROM ATTACHMENTS WHERE TITLE LIKE '%<ATTACHMENTNAME>%'

Last modified on Jan 14, 2020

Was this helpful?

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