Performance: File upload (single file)
MEDIUM IMPACT
This affects the page load speed and interaction responsiveness when uploading a single file through the frontend to the backend.
from fastapi import FastAPI, File, UploadFile app = FastAPI() @app.post('/upload') async def upload_file(file: UploadFile = File(...)): contents = await file.read() return {'file_size': len(contents)}
from fastapi import FastAPI, File app = FastAPI() @app.post('/upload') async def upload_file(file: bytes = File(...)): # process file bytes directly return {'file_size': len(file)}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Reading file as bytes (File(...)) | Minimal | 0 | 0 | [X] Bad |
| Using UploadFile with async read | Minimal | 0 | 0 | [OK] Good |