# Upload a Knowledge Document

`POST /api/knowledge/documents/hub-upload`

### Overview
Stores the original file in GCS, registers the document and starts the parser job (parse, chunk, embed, index). Returns immediately with status `uploaded` or `processing`; poll `GET /hub-documents/{id}` until `processed` or `failed`. Active when `KNOWLEDGE_BACKEND=parser`.

### Authentication & Headers
- **Auth**: Bearer Token (rejected for Auditor)
- **Content-Type**: `multipart/form-data`

### Form Fields
- **`file`** *(required)*: `pdf, doc, docx, xls, xlsx, ppt, pptx, txt, md, csv`, up to `KNOWLEDGE_MAX_UPLOAD_MB`.
- **`description`, `categories`, `keywords`** *(optional)*.
- **`visibility`** *(`private` default | `internal`)*, **`share_permission`** *(`use` default | `view`)*, **`share_expires_at`** *(ISO-8601, future)*.
- **`grantee_user_ids`, `grantee_group_ids`** *(optional; JSON array, comma list or repeated field)*; **`role_group_ids`** is accepted and ignored.

## Request body

Content type: `multipart/form-data`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | string | yes |  |
| `description` | string \| null | no |  |
| `categories` | string \| null | no |  |
| `keywords` | string \| null | no |  |
| `visibility` | string \| null | no |  |
| `share_permission` | string \| null | no |  |
| `share_expires_at` | string \| null | no |  |
| `grantee_user_ids` | string[] \| null | no |  |
| `grantee_group_ids` | string[] \| null | no |  |
| `role_group_ids` | string[] \| null | no |  |
| `folder_path` | string \| null | no |  |

```json
{
  "file": "string",
  "description": "string",
  "categories": "string",
  "keywords": "string",
  "visibility": "string",
  "share_permission": "string",
  "share_expires_at": "string",
  "grantee_user_ids": [
    "string"
  ],
  "grantee_group_ids": [
    "string"
  ],
  "role_group_ids": [
    "string"
  ],
  "folder_path": "string"
}
```

## Responses

### 201 — Document registered (`status`: `uploaded` | `processing`)

```json
null
```

### 400 — Bad Request - The request parameters or headers are invalid (e.g. unsupported API-Version).

### 401 — Unauthorized - Missing, invalid, or expired JWT Bearer token.

### 403 — Forbidden - Insufficient role permissions or resource access denied by RBAC policy.

### 404 — Not Found - The requested resource ID was not found.

### 413 — File exceeds the size limit

### 415 — Unsupported file extension

### 422 — Invalid file content or access fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | object[] | no |  |
| `detail[].loc` | string | integer[] | yes |  |
| `detail[].msg` | string | yes |  |
| `detail[].type` | string | yes |  |
| `detail[].input` | object | no |  |
| `detail[].ctx` | object | no |  |

```json
{
  "detail": [
    {
      "loc": [
        null
      ],
      "msg": "string",
      "type": "string",
      "input": null,
      "ctx": {}
    }
  ]
}
```

### 503 — File storage unavailable

## Example

```bash
curl -X POST "$PINTER_URL/api/knowledge/documents/hub-upload" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```
