newAttachment

suspend fun newAttachment(path: String, metadata: Map<String, String> = emptyMap()): DittoAttachment

Creates a new attachment, which can then be inserted into a document.

The file residing at the provided path will be copied into the Ditto's store. The DittoAttachment object that is returned is what you can then use to insert an attachment into a document.

You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.

Below is a snippet to show how you can use the newAttachment functionality to insert an attachment into a document.

val attachment = store.newAttachment(fileInputStream)
val docId = collection.insert(mapOf("attachment" to attachment, "other" to "string"))

Java sees this as newAttachment(String, Continuation) and newAttachment(String, Map, Continuation).

Return

a DittoAttachment object, which can be used to insert the attachment into a document.

Since

4.6.0

Parameters

path

the path to the file that you want to create an attachment with.

metadata

metadata relating to the attachment.


suspend fun newAttachment(inputStream: InputStream, metadata: Map<String, String> = emptyMap()): DittoAttachment

Creates a new attachment, which can then be inserted into a document.

The file that the input stream relates to will be copied into Ditto's store. The DittoAttachment object that is returned is what you can then use to insert an attachment into a document.

You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.

Note that the input stream provided will be closed once it has been read from.

Below is a snippet to show how you can use the newAttachment functionality to insert an attachment into a document.

val attachment = store.newAttachment(fileInputStream)
val docId = collection.insert(mapOf("attachment" to attachment, "other" to "string"))

Java sees this as newAttachment(String, Continuation) and newAttachment(String, Map, Continuation).

Return

a DittoAttachment object, which can be used to insert the attachment into a document.

Since

4.6.0

Parameters

inputStream

an input stream for the file that you want to create an attachment with.

metadata

metadata relating to the attachment.