> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiIyZjUzYjU5ZS0zNDA4LTRlNzQtODEwMS0wNzk5MTQ1YTBhYjgiLCJleHAiOjE3Nzg0OTUxMzYsImlhdCI6MTc3ODQ5NDgzNn0.0unNXksNQtfPiGvsaPbQm5uXpY5iuUUMVwzE4UVOuCg
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 多部分文件上传

多部分请求将一个或多个数据集组合到单个请求体中，通过边界分隔。
您通常使用这些请求进行文件上传，以及在单个请求中传输多种类型的数据
（例如，文件和 JSON 对象一起传输）。

```yml title="openapi.yml" maxLines=0 {12-24}
paths:
  /upload:
    post:
      summary: Upload a file
      description: Upload a file using multipart/form-data encoding
      operationId: uploadFile
      tags:
        - file
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                  description: The file to upload
                description:
                  type: string
                  description: A description of the file (optional)
              required:
                - file
      responses:
        "200":
          description: Successful upload
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  fileId:
                    type: string
```

任何使用 `multipart/form-data` 内容类型定义的请求体都将被视为多部分请求。在给定的多部分请求中，具有 `format:binary` 的字符串参数将表示任意文件。

## 文件数组

如果您的端点支持文件数组，那么您的请求体必须使用数组类型。

```yml openapi.yml {12-17}
paths:
  /upload:
    post:
      summary: Upload multiple files
      operationId: uploadFiles
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                files:
                  type: array
                  items:
                    type: string
                    format: binary
                  description: An array of files to upload
```