<span id="上传访客附件"></span>

# Upload a visitor attachment

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Validates visitor and conversation first, then reserves the entire multipart request length. Request limit: 201 MiB. Publications share a 1 GiB rolling 24-hour budget and a 100-reservation attempt limit. Failed/abandoned attempts still count. Returned files and file_token are staged, not yet associated with model runs. Sending attachments requires canonical parts/attachments and each file's credential.


```http
POST https://api.moi.matrixorigin.cn/v5/public/webapp/files
```

<span id="调用前准备"></span>

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`; use the corresponding product API URL for a dedicated deployment.

[Prepare links and visitor identity in the same environment](identity-lifecycle.md#prepare). Do not supply a product PAT or workspace request headers.

<span id="请求"></span>

## Request

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl --request POST \
  "$BASE_URL/public/webapp/files?webapp=$AGENT_ID&t=$WEBAPP_TOKEN&s=$WEBAPP_SESSION&conversation_id=$CONVERSATION_ID" \
  --form "file=@$UPLOAD_FILE"
```

:::::
:::::{tab-item} Parameters

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `webapp` | Queries | string | Yes | Agent ID associated with the link. |
| `t` | Queries | string | Yes | Currently valid publication token. For short-code links, resolve first, then use the short code as t. |
| `s` | Queries | string | Yes | Visitor session credential for the same publication. |
| `conversation_id` | Queries | string | Yes | Current visitor's active conversation ID. |
| `file` | Multipart form | file | Yes | File to upload; actual content at most 200 MiB. |

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 0,
  "data": {
    "file_id": "file-example",
    "workspace_id": "workspace-example",
    "volume_id": 1,
    "name": "example.txt",
    "size": 5,
    "md5": "example-md5",
    "file_token": "example-file-credential"
  }
}
```

:::::
:::::{tab-item} Fields

Success returns HTTP 200 and numeric code=0. Read data's [object descriptions](objects.md) alongside the example. The conversation creation example is only a field excerpt.

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error responses

[Public errors and identity handling](identity-lifecycle.md#errors) distinguishes unavailable/disabled links, invalid sessions, parameters, and system failures.
