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

# 上传文件

> POST /media/

在**管理 API** 主机 (`api.scanova.io`) 上上传文件，使用您的原始管理 API 密钥进行身份验证。

```
POST https://api.scanova.io/media/
Authorization: 401f7ac837da42b97f613d789819ff93537bee6a
Content-Type: multipart/form-data
```

<ParamField body="file" type="file" required>
  要上传的文件。`file` 或 `upload` 二者必须提供其一。
</ParamField>

<ParamField body="upload" type="file">
  `file` 的别名 —— 提供其中一个即可。
</ParamField>

<ParamField body="file_type" type="string">
  以逗号分隔的类别，用于限制验证范围（`image`、`video`、`audio`、`pdf`、`doc`、`script`）。各类别的验收标准见[列出允许的文件类型](/zh/api-reference/management-api/user-media/allowed-files)。
</ParamField>

<ParamField body="in_use" type="string">
  此文件的用途：`avatar`、`qr_logo`、`qr_content`、`poster`、`qr_image`、`profile_pic`、`banner`、`smart`、`thumbnail`，或 `unknown`（默认）。
</ParamField>

<ParamField body="category" type="string">
  自由文本类别标签，例如 QR 类别 slug 或 `"Custom Design"`。
</ParamField>

<ParamField body="bulk_media" type="integer">
  一个批量媒体批次的 id，来自[创建批量媒体批次](/zh/api-reference/management-api/user-media/bulk-create)，用于将此上传与其关联。
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.scanova.io/media/" \
    -H "Authorization: 401f7ac837da42b97f613d789819ff93537bee6a" \
    -F "file=@logo.png" \
    -F "in_use=qr_logo" \
    -F "category=custom-design"
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "id": 4821,
    "file": "media/uploads/104/2026/09/20260908_512873_logo.png",
    "upload": null,
    "file_name": "20260908_512873_logo.png",
    "size": 48213,
    "human_readable_size": "47.08 KB",
    "original_name": "logo.png",
    "bulk_media": null,
    "mime_type": "image/png",
    "file_type": "png",
    "in_use": "qr_logo",
    "category": "custom-design",
    "created": "2026-09-08T10:15:32.120Z",
    "modified": "2026-09-08T10:15:32.120Z"
  }
  ```
</ResponseExample>

## 验证

* **扩展名和 MIME 类型**必须同时存在于检测到的 `file_type` 类别的允许列表中 —— 不一致的情况（例如实际是 PDF 却带有 `.png` 扩展名）将被拒绝。
* **大小**根据类别限制进行检查 —— 但 `pdf`/`doc` 文件除外，此时账户的计划配额 `DOCUMENT_FILE_SIZE`（以 MB 为单位）会覆盖静态上限。
* **JavaScript** (`.js`) 上传会在大小检查之前被解析，以确认其为语法有效的 JS。
* **SVG** 会被扫描是否嵌入了脚本，若发现则拒绝。
* 没有扩展名的文件一律被拒绝。

上述任何验证错误都会返回 `400`，并附带说明问题的消息。

## 相关内容

* [列出已上传文件](/zh/api-reference/management-api/user-media/list) —— 查看已上传的内容。
* [列出允许的文件类型](/zh/api-reference/management-api/user-media/allowed-files) —— 在上传前进行客户端验证。
* [删除文件](/zh/api-reference/management-api/user-media/delete) —— 删除一个文件。
* [管理 API 概述](/zh/api-reference/management-api/overview) —— 适用于此端点的身份验证方案和配额规则。


## OpenAPI

````yaml api-reference/openapi/management-api.json POST /media/
openapi: 3.1.0
info:
  title: Scanova Management API (v2)
  description: >-
    The complete Scanova Management API — every endpoint available at
    api.scanova.io (QR codes, folders, tags, leads, forms, analytics, plans,
    shared users & roles), plus the token-creation and usage-stats endpoints
    used to authenticate against it. Every path and request/response shape below
    was verified live against a real API key and the actual running backend
    (Phase 7, 2026-08-16) — not guessed from reading urls.py alone.
  version: 2.0.0
servers:
  - url: https://api.scanova.io
    description: Management API — QR/folder/tag/lead/form/analytics/plans endpoints
security:
  - apiKeyAuth: []
paths:
  /media/:
    post:
      summary: Upload a file
      description: >-
        Multipart file upload. Validates extension, MIME type, and size against
        the file_type's allow-list (or the account's DOCUMENT_FILE_SIZE quota
        for pdf/doc files); JavaScript uploads are additionally parsed to
        confirm they're syntactically valid, and SVGs are scanned for embedded
        scripts.
      operationId: uploadMedia
      requestBody:
        content:
          multipart/form-data:
            example:
              file: (binary file)
              in_use: qr_logo
              category: custom-design
      responses:
        '201':
          description: File uploaded.
          content:
            application/json:
              example:
                id: 4821
                file: media/uploads/104/2026/09/20260908_512873_logo.png
                upload: null
                file_name: 20260908_512873_logo.png
                size: 48213
                human_readable_size: 47.08 KB
                original_name: logo.png
                bulk_media: null
                mime_type: image/png
                file_type: png
                in_use: qr_logo
                category: custom-design
                created: '2026-09-08T10:15:32.120Z'
                modified: '2026-09-08T10:15:32.120Z'
        '400':
          description: >-
            Missing file, no extension, MIME/extension mismatch, invalid
            JavaScript, SVG failed the XSS scan, or file size exceeds the
            allowed limit.
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Send your Management API key as the raw value of the Authorization
        header — no "Bearer " or "Token " prefix, and no other characters.
        Example: `Authorization: 401f7ac837da42b97f613d789819ff93537bee6a`. A
        header containing more than one space-separated part is rejected
        outright. Requests also require the request's Host header to be the
        management API host (e.g. api.scanova.io) — the same key sent to the
        regular API host will not authenticate.

````