# Links to attachments in Confluence storage format

URL: https://goingstellar.ro/reference/confluence-storage-format/attachment-links/

An attachment link is an ac:link containing ri:attachment with the file name. Confluence has no ADF link mark for it, so the Cloud editor rewrites it as a view-file macro, which changes how the file appears. A file that cannot be found gives an unresolved link or a macro error.

## Storage format

```xml
<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>
```

## As ADF (Confluence Cloud)

The ADF that Confluence Cloud builds for:

```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>
```

```json
{
 "type": "doc",
 "content": [
  {
   "type": "paragraph",
   "content": [
    {
     "type": "mediaInline",
     "attrs": {
      "id": "UNKNOWN_MEDIA_ID",
      "collection": "",
      "__fileName": "atlassian_logo.gif"
     }
    }
   ]
  }
 ],
 "version": 1
}
```

## Examples

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>
```

The attachment link example from the storage format page.

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>
```

Showing an attached PDF with the view file macro, and what the page displays when the file 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.

Storage format sent:

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

An attached image placed with ac:image, which is the other way to refer to an attachment.

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.

## What changes in conversion

- An ac:link to an attachment is saved through ADF as a mediaInline node. Storage comes back as a view-file macro holding the same ri:attachment, with a version-at-save attribute added.
- The custom link text is lost in that step. The text Link to a Confluence Attachment does not return, and the macro shows the file by name.
- The view file macro itself survives the round trip unchanged, including its ri:attachment parameter.

## Pitfalls

- An ac:link whose ri:attachment is not found renders as an unresolved link with a # address, with no error message, so the problem is easy to miss.
- The view file macro prints an error naming the file when the attachment is missing. The file name must match exactly, with its extension.
- In the runs, an ac:image of atlassian_logo.gif rendered with a download address, while the ac:link to the same name rendered as unresolved. Do not use the view of an attachment link to prove the file is found.

## Related

- [Attached images](https://goingstellar.ro/reference/confluence-storage-format/attached-images/)
- [<ac:link> to a page](https://goingstellar.ro/reference/confluence-storage-format/page-links/)
- [Link bodies: plain text and rich](https://goingstellar.ro/reference/confluence-storage-format/link-bodies/)
- [<a href> external links](https://goingstellar.ro/reference/confluence-storage-format/external-links/)
- [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/)

