aps-agent/docs/development/upload-limit.md

30 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Web 上传 413 排查与修复
## 现象
- 上传约 2MB 的 `5060102101-001-e(1).dxf` 提示“文件超过上传大小限制,单文件最大 100MB”。
- 应用层上限实际为 `PROJECT_UPLOAD_MAX_BYTES = 100 * 1024 * 1024`(100MB),2MB 文件不会触发应用层限制。
## 原因
- Web 发布环境通常在 Nginx 或其他反向代理前面。
- Nginx 默认 `client_max_body_size` 为 1m,超过 1MB 的请求会在到达 FastAPI 前直接返回 `413 Request Entity Too Large`。
- 前端把 413 映射成了“单文件最大 100MB”,因此看起来像应用层限制。
## 修复
- 在 Nginx `http/server` 层设置:
```nginx
client_max_body_size 100m;
```
- 仓库提供参考配置:[deploy/nginx-aps.conf](../../deploy/nginx-aps.conf),含 `/api/` 反代与 100m 上传上限。
- 如果使用其他网关(Caddy/云负载均衡/Ingress),同样将请求体大小上限设为 100m 以上。
- 修改后执行 `nginx -t && nginx -s reload`(容器内则重建/重启 Web 镜像)。
## 验证
- 本地直连 FastAPI(不走 Nginx)上传 2.5MB DXF 应返回 200:见 `tests/golden/test_drawing_manage.py::test_two_mb_upload_is_not_blocked_by_app_limit`。
- 走 Nginx 部署后,浏览器上传同一文件应不再出现 413。