<span id="上传工作区文件记录"></span>

# Upload a workspace file record

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

Upload a workspace file record without associating it with a volume.

```text
POST https://api.moi.matrixorigin.cn/v5/workspaces/{id}/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 a personal access token for the target workspace. WORKSPACE_ID must match the path workspace; FILE_ID comes from actual file results. BASE_URL includes the product prefix in the same environment. Example files/IDs are placeholders.

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

## Request parameters

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

```bash
curl --fail-with-body -sS -X POST "$BASE_URL/workspaces/$WORKSPACE_ID/files" \
  -H "X-API-Key: $MOI_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -F "file=@$UPLOAD_FILE;type=text/plain" \
  -F "initial_ref_count=0"
```

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | file | Yes | Multipart file. |
| `initial_ref_count` | integer | No | Initial reference count, default 0, range 0–2147483647. |

Success uses HTTP 201 and numeric code=0. Uploading alone neither creates a volume association nor publishes an agent artifact. Positive reference counts affect deletion.

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

<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",
    "original_name": "sample.txt",
    "size": 7,
    "md5": "5177a58dc65c8a14dc90c69db3bf3dd2"
  }
}
```

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

Success uses numeric code=0; data contains file_id, original_name, size, and md5. No msg field.

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

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

## Error responses

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

```json
{
  "code": 2,
  "message": "示例错误信息"
}
```

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

Invalid request fields return 400/2. Business upload failures use numeric code/message. Internal write failures may return 500/1.

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