# fastapi.exceptions.HTTPException: 413：请求实体过大

- **ID:** `python/fastapi-file-upload-too-large`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

上传文件超过服务器或反向代理的请求体大小限制（如 nginx client_max_body_size）。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   client_max_body_size 50m;
   ```
2. **** (85% 成功率)
   ```
   async for chunk in request.stream():
    await save_chunk(chunk)
   ```

## 无效尝试

- **** — FastAPI has no built-in limit; the block is at nginx/gunicorn. (90% 失败率)
- **** — Same payload will always exceed the limit. (85% 失败率)
