<span id="上传本地文件到知识库"></span>

# Upload local files

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

Upload local files for use in creating or appending knowledge base sources. Successful upload only means that the file has been saved, but does not mean that the content is retrievable.

```text
POST https://api.moi.matrixorigin.cn/v5/semantic-models/{model_id}/local-files/upload
```

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

## Before you call this API

First [query the knowledge base list](list-knowledge-bases.md) to obtain the target knowledge base ID. Prepare a personal access token and target workspace ID that has access to the target workspace.

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

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

```bash
curl -X POST "https://api.moi.matrixorigin.cn/v5/semantic-models/$MODEL_ID/local-files/upload" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -F "file=@./product-guide.pdf"
```

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

Submit the file using `multipart/form-data`. The example's `curl -F` sets the header; do not add `Content-Type: application/json`.

<span id="路径参数"></span>

### Path parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `model_id` | integer | Yes | Target knowledge base ID. |

<span id="表单字段"></span>

### Form fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | file | Yes | The local file to upload. |

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


The returned identifier is a file ID, not a source record ID. Submit it with its original filename as `local_file` when creating or appending sources. Uploading does not automatically append sources or complete parsing/indexing. Knowledge base upload prevalidation currently rejects SVG files.

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

## Successful response

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

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "file_id": "file_01"
  }
}
```

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


| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data` | object | Data returned by this operation. |
| `data.file_id` | string | ID of the uploaded file; use this value when adding a local file source. |


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


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

## Error response

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

```json
{
  "code": "ErrParamInvalid",
  "msg": "file is required",
  "data": null
}
```

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

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | Error code. |
| `msg` | string | Error description. |
| `data` | null | `null` on error. |

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