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