Platform Manual
Data Types

ATTACHMENT

With the ATTACHMENT data type, you can associate very large amounts of binary data, such as an image, video, a deeply embedded document, and so on, with a document and sync across peers without conflict.

Unlike documents, ATTACHMENTS store data outside of the Ditto store running locally in the end-user environment and must be explicitly fetched to sync across distributed peers.

Merge Strategy: Last-Write-Wins



Ensuring Uninterrupted Fetching



Creating and Fetching Attachments

The following snippet demonstrates a use case for leveraging the attachment CRDT, as well as the step-by-step process for creating and fetching the attachment:

If developing in Swift, for a tutorial on how to work with an attachment in a chat app, see Attachments: Chat App.

The following snippet demonstrates the process for creating, associating, and fetching anattachment.

  1. Define a collection named 'foo'.
  2. Using Base64-encoded image data and metadata, create an attachment object .
  3. INSERT a document with an attachment in the collection.
  4. Later, retrieve the document by _id and fetch the attachment using an attachmentFetcher.
Kotlin
JS
Java
C#
C++
Rust




Updated 12 Mar 2024
Did this page help you?