Attachment is a file input component. It represents selected files as a list of attachment dictionaries.
Contract¶
| Property | Type | Notes |
|---|---|---|
label |
str |
Input label. |
accept |
str |
Browser file accept filter, such as .pdf,.txt. |
multiple |
bool |
Allows more than one file. |
ingest |
bool |
Defaults to true. When false, uploaded files are not enqueued for knowledge extraction. |
value |
list[dict] |
Current attachment entries. |
action / params |
str or action object / dict |
Optional action emitted on change. Action objects can include confirm. |
Value collected by actions: list[dict].
Action Confirmation¶
Use an action object with confirm to require confirmation before the attachment list change is dispatched. If the user cancels the dialog, no backend action is sent and the attachment list keeps its previous value.
The component test page exposes an attachment action counter and the last received payload so dispatch can be checked directly after confirming.
field = sdk.ui.Attachment(
"confirm_python_attachment",
label=sdk.i18n.t("components.attachment.confirm.python_label"),
accept=".txt,.pdf,image/*",
multiple=True,
)
field.set_prop(
"action",
{
"name": "components.attachment_confirm_action",
"context": {"source": "python_attachment"},
"confirm": {
"text": sdk.i18n.t("components.attachment.confirm.prompt"),
"confirm_text": sdk.i18n.t("components.attachment.confirm.accept"),
"cancel_text": sdk.i18n.t("components.attachment.confirm.cancel"),
},
},
)- kind: Attachment
id: confirm_yaml_attachment
label: "@t/components.attachment.confirm.yaml_label"
accept: ".txt,.pdf,image/*"
multiple: true
value: []
action:
name: components.attachment_confirm_action
context:
source: yaml_attachment
confirm:
text: "@t/components.attachment.confirm.prompt"
confirm_text: "@t/components.attachment.confirm.accept"
cancel_text: "@t/components.attachment.confirm.cancel"Example¶
field = sdk.ui.Attachment(
"components_test_forms_attachment_store",
label="Attachment",
accept=".pdf,.txt",
multiple=True,
value=bound.store("/components_test/forms/attachment/store", scope="page", default=[]),
)- kind: Attachment
id: components_test_forms_yaml_attachment
label: "Attachment YAML"
value: {type: store, scope: page, path: /components_test/forms/attachment/store, default: []}
accept: ".pdf,.txt"
ingest: true
multiple: trueRuntime¶
Use collect_input_ids to read the current attachment list. Use value.set, value.append, value.remove, stateUpdate, or dataModelUpdate depending on whether the action replaces or mutates the list.