Document Model
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, 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 creating, associating, and fetching an ATTACHMENT.

  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.
Swift
Kotlin
JS
Java
C#
C++
Rust
Dart (beta)




Updated 06 Aug 2024
Did this page help you?