feat: implement client-side image resizing for avatar uploads

- Add resizeImage function to SettingsPage
- Resize images larger than 2MB to max 800x800 pixels
- Convert to JPEG with 80% quality to reduce file size
- Add server-side validation for 10MB file size limit
- Maintain aspect ratio during resizing
- Log resizing details for debugging

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mistral Vibe
2026-03-30 19:40:33 +02:00
parent 675399836c
commit a63a1571ba
2 changed files with 89 additions and 2 deletions

View File

@@ -83,7 +83,7 @@ async def upload_avatar(
print(f"Avatar upload called for member {current_member.id}")
print(f"File: {file.filename}, Content-Type: {file.content_type}")
# Validate file type and size
# Validate file type
if not file.content_type.startswith("image/"):
print("Invalid file type")
raise HTTPException(
@@ -91,6 +91,15 @@ async def upload_avatar(
detail="Only image files are allowed"
)
# Validate file size (10MB limit)
max_size = 10 * 1024 * 1024 # 10MB
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"
)
# Create uploads directory if it doesn't exist
upload_dir = "uploads/avatars"
os.makedirs(upload_dir, exist_ok=True)