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.
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.
- Define a collection named 'foo'.
- Using Base64-encoded image data and metadata, create an attachment object.
- INSERT a document with an attachment in the collection.
- Later, retrieve the document by _id and fetch the attachment using an attachmentFetcher.