---
title: 创建 File Upload
url: https://runapi.ai/zh-CN/docs/api/files/create.md
canonical: https://runapi.ai/zh-CN/docs/api/files/create
locale: zh-CN
---

# 创建 File Upload

上传一个本地文件、远程 HTTPS URL 或 base64 来源，并获得临时 URL。

## 端点

POST /api/v1/files

基础 URL: https://runapi.ai

API 版本: v1

身份验证: Authorization: Bearer YOUR_API_KEY

## 请求

只能在列出的请求位置发送值。

### application/json - Base64 source

```json
{
  "file_name": {
    "description": "Optional filename for the created File Upload.",
    "required": false,
    "type": "string"
  },
  "source": {
    "description": "Base64-encoded source bytes.",
    "properties": {
      "data": {
        "description": "Base64 data",
        "required": true,
        "type": "string"
      },
      "type": {
        "description": "Selects the base64 source representation.",
        "required": true,
        "type": "string"
      }
    },
    "required": true,
    "type": "object"
  }
}
```

### application/json - URL source

```json
{
  "file_name": {
    "description": "Optional filename for the created File Upload.",
    "required": false,
    "type": "string"
  },
  "source": {
    "description": "Remote HTTPS source to download.",
    "properties": {
      "type": {
        "description": "Selects the URL source representation.",
        "required": true,
        "type": "string"
      },
      "url": {
        "description": "Public HTTPS URL to download.",
        "format": "uri",
        "required": true,
        "type": "string"
      }
    },
    "required": true,
    "type": "object"
  }
}
```

### multipart/form-data

```json
{
  "file": {
    "description": "Local file bytes to upload.",
    "format": "binary",
    "required": true,
    "type": "string"
  },
  "file_name": {
    "description": "Optional filename for the created File Upload.",
    "required": false,
    "type": "string"
  }
}
```

## 成功响应

HTTP 201 - POST /api/v1/files

```json
{
  "created_at": "2026-07-27T10:00:00.000Z",
  "expires_at": "2026-07-27T11:00:00.000Z",
  "file_name": "mask.png",
  "mime_type": "image/png",
  "size_bytes": 204800,
  "url": "https://file.runapi.ai/temp/user-uploads/mask.png"
}
```

## 错误响应 (401)

HTTP 401

```json
{
  "error": {
    "code": "authentication_required",
    "message": "Authentication required"
  }
}
```

## 错误响应 (403)

HTTP 403

```json
{
  "error": {
    "code": "standard_api_key_required",
    "message": "Standard API key required"
  }
}
```

## 错误响应 (400)

HTTP 400

```json
{
  "error": {
    "code": "invalid_source",
    "message": "Only HTTPS URLs are allowed"
  }
}
```

## 错误响应 (408)

HTTP 408

```json
{
  "error": {
    "code": "invalid_source",
    "message": "Download timeout"
  }
}
```

## 错误响应 (413)

HTTP 413

```json
{
  "error": {
    "code": "file_too_large",
    "message": "File size exceeds the maximum allowed size"
  }
}
```

## 错误响应 (415)

HTTP 415

```json
{
  "error": {
    "code": "unsupported_media_type",
    "message": "This content type is not supported"
  }
}
```

## 错误响应 (422)

HTTP 422

```json
{
  "error": {
    "code": "upload_failed",
    "message": "File upload failed. Please try again."
  }
}
```

## 错误响应 (429)

HTTP 429

```json
{
  "error": {
    "code": "rate_limited",
    "message": "Too many file uploads for this account. Please retry later."
  }
}
```

## cURL 示例



### curl

```curl
curl -X POST https://runapi.ai/api/v1/files \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"source":{"type":"url","url":"https://cdn.runapi.ai/public/samples/mask.png"},"file_name":"mask.png"}'
```

## 相关参考

- [文件](/docs/api/files)
- [File Upload 对象](/docs/api/files/object)
