# Create file

Associates one or more existing file records to the specified volume.

```text
POST https://moi.matrixorigin.cn/newmoi/catalog/file/create
```

## Preparation before calling

First [upload the file](upload-file.md) to obtain the file ID, and [query the object](list-database-objects.md) in the database to obtain the target volume ID]. Prepare a personal access token, target workspace ID, target volume ID, and file ID that has access to the target workspace.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.
- `$VOLUME_ID`: Target volume ID.
- `$FILE_ID`: The file ID to associate to the volume.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/catalog/file/create" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "volume_id": '"$VOLUME_ID"',
    "file_ids": ["'"$FILE_ID"'"]
  }'
```

## Request body

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `volume_id` | integer | Yes | Target volume ID. |
| `file_ids` | array[string] | Yes | List of file IDs to associate. |

## Successful response

Returns `200` on success, `data` is `null`. This response indicates that the file is associated with the specified volume.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": null
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data` | null | Fixed to `null` when the association is successful. |

## Error response

```json
{
  "code": "ErrParamInvalid",
  "msg": "请求参数无效",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - Invalid request body, volume ID, or file ID.
  - Check `volume_id` and `file_ids`.
* - `403`
  - `ErrForbidden`
  - The current identity does not have write permissions to the target root volume.
  - Use credentials with write access, or contact your administrator for authorization.
* - `404`
  - `ErrNotFound`
  - The volume or file does not exist.
  - Check volume ID and file ID.
* - `500`
  - `ErrServer`
  - The service cannot associate the file.
  - Record the request time and error message and try again; if it continues to fail, contact support.
```

## Follow-up operations

[Query file list](list-files.md) Confirm that the file is associated with the volume.
