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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user