Unable to copy a Confluence page due to attachment size mismatch

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

Copying a page will fail with an error that the attachment size is different in the filesystem and in the database.

Diagnosis

In the logs something like this will be visible:

1 2 3 4 5 6 7 8 com.atlassian.confluence.pages.attachments.AttachmentDataStreamSizeMismatchException: Attachment data stream contains a different number of bytes to the declared size of the attachment. Expected: 130192, actual: 130203 at com.atlassian.confluence.pages.persistence.dao.filesystem.FileSystemAttachmentDataUtil.writeStreamToFile(FileSystemAttachmentDataUtil.java:42) at com.atlassian.confluence.pages.persistence.dao.filesystem.HierarchicalMultiStreamAttachmentDataFileSystem.saveAttachmentData(HierarchicalMultiStreamAttachmentDataFileSystem.java:104) at com.atlassian.confluence.pages.persistence.dao.filesystem.FileSystemAttachmentDataDao.saveDataForAttachment(FileSystemAttachmentDataDao.java:150) at com.atlassian.confluence.pages.persistence.dao.filesystem.FileSystemAttachmentDataDao.saveDataForAttachment(FileSystemAttachmentDataDao.java:120) at com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao.saveNewAttachment(AbstractHibernateAttachmentDao.java:363) at com.atlassian.confluence.pages.attachments.CachingAttachmentDao.saveNewAttachment(CachingAttachmentDao.java:202) at com.atlassian.confluence.pages.DefaultAttachmentManager.saveNewAttachment(DefaultAttachmentManager.java:252)

Cause

If the size of the attachment is different in the database "contentproperties" table and on the file system, then the issue will be observed when we try to copy the page.

Solution

The solution is simply to locate the affected attachment, download it and attach it again to the page.

To locate the affected attachment:

  • Locate the pageid (eg. 22334455).

  • Then use the "Expected" value from the stack trace ( from this stack trace that is 130192) and pageid in this query to find the attachment name:

    1 select title from content where pageid=22334455 and contentid in (select contentid from contentproperties where propertyname='FILESIZE' and longval=130192);
  • Once you locate the attachment name, download it from the page and re-upload it again.

  • This should fix the issue.

The same behavior was observed with files created by Draw.io macro, which are stored as attachments.

  • The issue on that case can be solve by exporting the macro content and re-importing it.

Updated on March 18, 2025

Still need help?

The Atlassian Community is here for you.