fix: improve file size handling and error messages

- Reduce server-side limit to 5MB for upload endpoint
- Increase client-side resizing threshold to 4MB
- Add specific error handling for 413 responses
- Add more detailed logging for file sizes
- Improve user error messages

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mistral Vibe
2026-03-30 19:43:22 +02:00
parent a63a1571ba
commit 26f45009d4
2 changed files with 15 additions and 6 deletions

View File

@@ -91,13 +91,13 @@ async def upload_avatar(
detail="Only image files are allowed"
)
# Validate file size (10MB limit)
max_size = 10 * 1024 * 1024 # 10MB
# Validate file size (5MB limit for upload endpoint)
max_size = 5 * 1024 * 1024 # 5MB
if file.size > max_size:
print(f"File too large: {file.size} bytes (max {max_size})")
raise HTTPException(
status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
detail=f"File too large. Maximum size is {max_size / 1024 / 1024}MB"
detail=f"File too large. Maximum size is {max_size / 1024 / 1024}MB. Please resize your image and try again."
)
# Create uploads directory if it doesn't exist