# Create file

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

```text
POST $CLOUDSIGMA_API_BASE/catalog/file/create
```

## Before you call this API

Configure the [regional API endpoint and authentication](https://omnifabric.cloudsigma.com/docs/developer/endpoints-and-authentication.html.md), and select the target workspace.

First [upload the file](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/catalog/upload-file.html.md) to obtain the file ID, and [query the object](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/catalog/list-database-objects.html.md) in the database to obtain the target volume ID].

Set the operation-specific values used in the request:

- `$VOLUME_ID`: Target volume ID.
- `$FILE_ID`: The file ID to associate to the volume.

## Request example

```bash
curl -X POST "$CLOUDSIGMA_API_BASE/catalog/file/create" \
  -H "X-API-Key: $CLOUDSIGMA_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](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/catalog/list-files.html.md) Confirm that the file is associated with the volume.
