# Attached images in Confluence storage format

URL: https://goingstellar.ro/reference/confluence-storage-format/attached-images/

An attached image is an ac:image containing ri:attachment with the file name. Confluence adds ri:version-at-save on save. The ADF form is a mediaSingle holding a file media node, with a collection named after the page id.

## Storage format

```xml
<ac:image>
<ri:attachment ri:filename="atlassian_logo.gif" />
</ac:image>
```

## As ADF (Confluence Cloud)

The ADF that Confluence Cloud builds for:

```xml
<ac:image><ri:attachment ri:filename="atlassian_logo.gif" /></ac:image>
```

```json
{
 "type": "doc",
 "content": [
  {
   "type": "mediaSingle",
   "attrs": {
    "layout": "align-start"
   },
   "content": [
    {
     "type": "media",
     "attrs": {
      "__fileMimeType": "image/gif",
      "id": "UNKNOWN_MEDIA_ID",
      "collection": "contentId-<page id>",
      "type": "file",
      "__fileName": "atlassian_logo.gif"
     }
    }
   ]
  }
 ],
 "version": 1
}
```

## Examples

Storage format sent:

```xml
<ac:image><ri:attachment ri:filename="atlassian_logo.gif" /></ac:image>
```

The attached image example from the storage format page.

Rendered view (HTML):

```html
<span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" loading="lazy" src="https://your-site.atlassian.net/wiki/download/attachments/<page id>/atlassian_logo.gif?version=1&amp;modificationDate=1795971932009&amp;cacheVersion=1&amp;api=v2" data-image-src="https://your-site.atlassian.net/wiki/download/attachments/<page id>/atlassian_logo.gif?version=1&amp;modificationDate=1795971932009&amp;cacheVersion=1&amp;api=v2" data-unresolved-comment-count="0" data-linked-resource-id="<attachment id>" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="atlassian_logo.gif" data-base-url="https://your-site.atlassian.net/wiki" data-linked-resource-content-type="application/octet-stream" data-linked-resource-container-id="<page id>" data-linked-resource-container-version="116" data-media-id="UNKNOWN_MEDIA_ID" data-media-type="file"></span>
```

Storage format after the round trip through ADF:

```xml
<ac:image ac:align="left" ac:layout="align-start"><ri:attachment ri:filename="atlassian_logo.gif" ri:version-at-save="1" /></ac:image>
```

Sent to Confluence Cloud on 29 Nov 2026.

Storage format sent:

```xml
<p><ac:link><ri:attachment ri:filename="atlassian_logo.gif" /><ac:plain-text-link-body><![CDATA[Link to a Confluence Attachment]]></ac:plain-text-link-body></ac:link></p>
```

An ac:link to the same file, which is converted differently from the image.

Rendered view (HTML):

```html
<p><a class="unresolved" href="#">Link to a Confluence Attachment</a></p>
```

Storage format after the round trip through ADF:

```xml
<p><ac:structured-macro ac:name="view-file" ac:schema-version="1" ac:macro-id="<id>"><ac:parameter ac:name="name"><ri:attachment ri:filename="atlassian_logo.gif" ri:version-at-save="1" /></ac:parameter></ac:structured-macro></p>
```

Sent to Confluence Cloud on 29 Nov 2026.

Storage format sent:

```xml
<ac:structured-macro ac:name="viewfile"><ac:parameter ac:name="name"><ri:attachment ri:filename="doc.pdf" /></ac:parameter></ac:structured-macro>
```

An attachment shown with a macro instead of an image, with a file that is not found.

Rendered view (HTML):

```html
<div class="error">Error rendering macro 'viewfile' : Failed to find attachment with Name doc.pdf</div>
```

Storage format after the round trip through ADF:

```xml
<ac:structured-macro ac:name="viewfile" ac:schema-version="1" ac:macro-id="<id>"><ac:parameter ac:name="name"><ri:attachment ri:filename="doc.pdf" /></ac:parameter></ac:structured-macro>
```

Sent to Confluence Cloud on 29 Nov 2026.

## What changes in conversion

- A save adds ri:version-at-save to the ri:attachment element, so the image is pinned to the attachment version at that time.
- The ADF form is a file media node with the file name, the mime type and a collection of the form contentId followed by the page id. The media id is a placeholder.
- An ADF save adds ac:align and ac:layout set to left and align-start, and leaves the ri:attachment element as it was.
- In the view, the img carries data attributes that identify the attachment, such as its resource id, version and type.

## Pitfalls

- The file name has to match the attachment name exactly. When no attachment is found, a link to it renders as unresolved, and the view file macro prints an error with the name it looked for.
- ri:version-at-save is written by Confluence on save, so hand-written markup does not need it.
- The numeric ids in the view are specific to the site and the page, so they must never be copied into another page.

## Related

- [<ac:image> from a URL](https://goingstellar.ro/reference/confluence-storage-format/external-images/)
- [Image attributes](https://goingstellar.ro/reference/confluence-storage-format/image-attributes/)
- [Links to attachments](https://goingstellar.ro/reference/confluence-storage-format/attachment-links/)
- [Link bodies: plain text and rich](https://goingstellar.ro/reference/confluence-storage-format/link-bodies/)
- [Storage format vs ADF](https://goingstellar.ro/reference/confluence-storage-format/storage-vs-adf/)

## Sources

- [Confluence storage format (Atlassian Documentation)](https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html)
- [Atlassian Document Format: document structure (Atlassian Developer)](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/)

