> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xpertai.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 上传附件

> 按 contexts.uploadFile() 使用的默认存储目标上传 multipart 文件。将返回的 FileAsset 句柄放入 input.message.input.files；其 id 与 storageFileId 不同。上传返回时，文件解析可能仍在进行。



## OpenAPI

````yaml /api/openapi.sdk.zh-Hans.json post /api/ai/contexts/file
openapi: 3.0.3
info:
  title: XpertAI SDK HTTP 接口
  version: 1.0.0
  description: >-
    SDK 指南使用的当前 HTTP 接口。使用服务端 API Key，通过 Authorization: Bearer <API_KEY> 或
    x-api-key 鉴权，不依赖 ChatKit。本参考覆盖指南中的案例，不代表 SDK 导出的所有方法都已实现；使用其他字段前请核对部署支持情况。
servers:
  - url: https://api.xpertai.cn
    description: XpertAI API，私有部署请替换为自己的 API 服务地址。
security:
  - ApiKeyBearer: []
  - ApiKeyHeader: []
tags:
  - name: Assistants
  - name: Threads
  - name: Runs
  - name: Contexts
  - name: Store
paths:
  /api/ai/contexts/file:
    post:
      tags:
        - Contexts
      summary: 上传附件
      description: >-
        按 contexts.uploadFile() 使用的默认存储目标上传 multipart 文件。将返回的 FileAsset 句柄放入
        input.message.input.files；其 id 与 storageFileId 不同。上传返回时，文件解析可能仍在进行。
      operationId: upload_file
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
              required:
                - file
      responses:
        '201':
          description: 请求成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentFile'
              example:
                id: 55555555-5555-4555-8555-555555555555
                storageFileId: 66666666-6666-4666-8666-666666666666
                originalName: manual.pdf
                mimeType: application/pdf
                parseStatus: pending
        '400':
          description: 请求参数、标识关联或操作状态不正确。
        '401':
          description: 缺少 API Key 或 API Key 无效。
        '403':
          description: 调用方无权访问目标资源。
        '404':
          description: 资源不存在或对调用方不可用。
components:
  schemas:
    AgentFile:
      type: object
      properties:
        id:
          type: string
          description: FileAsset ID。将返回的文件句柄放入 message.input.files。
        fileId:
          type: string
        storageFileId:
          type: string
          description: 知识库文档关联所需的 StorageFile ID，不能用 FileAsset ID 替代。
        url:
          type: string
        originalName:
          type: string
        size:
          type: integer
        mimeType:
          type: string
        status:
          type: string
        parseStatus:
          type: string
        parseMode:
          type: string
        purpose:
          type: string
      required:
        - id
  securitySchemes:
    ApiKeyBearer:
      type: http
      scheme: bearer
      description: 服务端 API Key，不要暴露到浏览器代码中。
    ApiKeyHeader:
      type: apiKey
      in: header
      name: x-api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.