ditto-lib / live.ditto / DittoCollection / newAttachment

newAttachment

@JvmOverloads 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 DittoKit'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 how you can use the newAttachment functionality to insert an attachment into a document.

if let attachment = collection.insert.newAttachment("/path/to/my/file.pdf") {
    let docID = try! collection.insert(["attachment": attachment, "other": "string"])
}

Parameters

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

metadata - metadata relating to the attachment.

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

@JvmOverloads 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 DittoKit'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 how you can use the newAttachment functionality to insert an attachment into a document.

if let attachment = collection.insert.newAttachment(fileInputStream) {
    let docID = try! collection.insert(["attachment": attachment, "other": "string"])
}

Parameters

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

metadata - metadata relating to the attachment.

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