# 上传文件

> 使用 API key 认证上传文件。

```yaml
openapi: 3.1.0
x-onerway-docs-version: original
x-onerway-spec-key: embedded-finance/files/upload-file
info:
  title: 上传文件
  version: original
  description: 使用 API key 认证上传文件。
servers:
  - url: https://sandbox-baas.onerway.com/embedded-finance
    description: sandbox
  - url: https://baas.onerway.com
    description: production
paths:
  /api/v2/upload/file:
    post:
      summary: 上传文件
      description: 使用 API key 认证上传文件。
      parameters:
        - name: apiKey
          in: header
          required: true
          description: 用于访问嵌入式金融 API 的 API key。
          schema:
            type: string
            description: 用于访问嵌入式金融 API 的 API key。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                fileName:
                  type: string
                  description: 随上传请求提交的文件名。
                  x-onerway-constraints:
                    - kind: range
                      max: 64
                      unit: 字符
                    - kind: rule
                      text: 使用原始文件名，或使用商户生成且保留文件扩展名的文件名。
                file:
                  type: string
                  description: 需要上传的文件二进制流。
                  x-onerway-constraints:
                    - kind: range
                      max: 15
                      unit: MB
                      text: 文件大小上限。
                    - kind: rule
                      text: 在该 form-data part 中发送实际文件二进制流，不要把本地文件路径字符串作为字段值提交。
              required:
                - fileName
                - file
            examples:
              default:
                summary: 上传文件
                value:
                  fileName: back.png
                  file: '@"/path/to/back.png"'
      responses:
        "200":
          description: 上传成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  respCode:
                    type: string
                    description: Onerway 返回的响应码；`20000` 表示上传成功。
                  respMsg:
                    type: string
                    description: 响应码对应的可读消息。
                  data:
                    type: object
                    properties:
                      merchantNo:
                        type: string
                        description: 上传文件所属的商户号。
                      fileId:
                        type: integer
                        description: 文件上传成功后返回的文件 ID。
                    description: 文件上传成功后返回的文件元数据。
              examples:
                success:
                  summary: 上传成功
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data:
                      merchantNo: 800***
                      fileId: 987654321
      security:
        - apiKeyAuth:
            []
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: apiKey
```
