Write attachment
write_attachmentUpdate a TriliumNext attachment by changing its metadata, replacing stored content from a URL, file, base64 or text, or editing text via search/replace blocks or a diff patch.
Instructions
Update an attachment: mode="metadata" changes role/mime/title/position; "replace" overwrites the body (path, URL, data URL, base64 or text; the stored mime is kept); "edit" applies "changes" or a "patch" to a text attachment (binary attachments must use "replace").
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"attachmentId": "<attachmentId>",
"mode": "<mode>"
},
"name": "write_attachment"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mime | No | New MIME type (metadata mode only). | |
| mode | Yes | Write mode. "metadata" — update role/mime/title/position only. "replace" — overwrite attachment content (accepts a file path, http(s) URL, data URL, base64, or raw text). "edit" — apply search/replace blocks (changes) or a unified diff (patch) to text content. | |
| role | No | New role (metadata mode only): "image" for pictures embedded in the note, "file" for downloadable files (Trilium accepts other values, but these are the two in normal use). | |
| patch | No | "edit" mode: single-file unified diff (with @@ hunks) against the stored text. | |
| title | No | New title/filename (metadata mode only). | |
| changes | No | "edit" mode: {old_string, new_string} blocks applied in order; each old_string must match the stored text exactly once ("" inserts at the start). | |
| content | No | New content for "replace" mode, in any form create_attachment content accepts (URL, data URL, base64, raw text, or a server-side file path when permitted). | |
| position | No | New position for ordering (metadata mode only). | |
| attachmentId | Yes | ID of the attachment to write to |