# 内存错误：无法分配形状为 (100000000,) 且数据类型为 float64 的数组

- **ID:** `python/starlette-memory-error-upload`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在 Starlette/FastAPI 端点中尝试一次性将大文件上传读入内存。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   Stream the file using UploadFile.read(chunk_size) in a loop and process chunks: while chunk := await file.read(1024*1024): process(chunk)
   ```
2. **** (80% 成功率)
   ```
   Use a temporary file on disk: with tempfile.NamedTemporaryFile(delete=False) as tmp: shutil.copyfileobj(file.file, tmp)
   ```

## 无效尝试

- **** — These don't affect Python's heap allocation for large numpy arrays; physical RAM is exhausted. (90% 失败率)
- **** — This loads the whole file into a bytes object, still causing memory pressure. (80% 失败率)
