# Starlette数据结构：413请求实体过大

- **ID:** `python/fastapi-upload-file-size-error`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

上传的文件超过服务器允许的最大大小，通常是由于Web服务器或框架的默认限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Configure the server limit, e.g., in Uvicorn: uvicorn app:app --limit-max-request-size 10485760
   ```
2. **** (95% 成功率)
   ```
   Check file size before processing: if file.size > MAX_SIZE:\n    raise HTTPException(413)
   ```

## 无效尝试

- **** — Reading the entire file into memory before checking size can cause memory issues. (80% 失败率)
- **** — Increasing the limit globally may affect other parts of the app. (60% 失败率)
