# Upload local files before creation

Upload local files before creating the knowledge base. If the upload is successful, only the file ID to be bound will be returned; it must be bound as the `local_file` source when [creating the knowledge base and adding the data source](create-knowledge-base-with-sources.md).

```text
POST https://moi.matrixorigin.cn/newmoi/semantic-models/local-files/upload
```

## Preparation before calling

Prepare a personal access token and workspace ID that has permission to create a knowledge base for the target workspace. The request uses `multipart/form-data`, and the form field name is fixed to `file`.

## Request example

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

## Successful response

Returns `200` on success.

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

| Field | Type | Description |
| --- | --- | --- |
| `data.file_id` | string | ID of the file to be bound. Pass `sources[]` along with the file name when creating the knowledge base. |

In field paths, `[]` means each item in an array. For example, `sources[]` means each item in `sources`.

## Common mistakes

| HTTP Status Codes | Error Codes | Common Causes | Recommended Actions |
| --- | --- | --- | --- |
| `400` | `ErrParamInvalid` | `file` was not submitted or the file name is empty. | Submit files using `-F "file=@/path/to/file"`. |
| `401` | `ErrUnauthorized` | The API Key is invalid or has expired. | Check API Key. |
| `403` | `ErrForbidden` | No workspace creation permission. | Check workspace authorization. |

## Follow-up operations

Call [Create knowledge base and add data source](create-knowledge-base-with-sources.md), and submit `data.file_id` and the original file name as the `local_file` source.
