Chandima Prabhath commited on
Commit ·
fe33638
1
Parent(s): e7b3e2b
Optimize profile picture upload by resizing and compressing images before upload
Browse files
main.py
CHANGED
|
@@ -346,7 +346,17 @@ def delete_existing_user(user_id: int, current_user: dict = Depends(get_current_
|
|
| 346 |
@user_router.post("/upload-profile-picture", response_model=UserOut)
|
| 347 |
async def upload_profile_picture(file: UploadFile = File(...), current_user: dict = Depends(get_current_user)):
|
| 348 |
try:
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
except Exception as e:
|
| 351 |
raise HTTPException(status_code=400, detail=f"Image upload failed: {str(e)}")
|
| 352 |
image_url = result.get("secure_url")
|
|
|
|
| 346 |
@user_router.post("/upload-profile-picture", response_model=UserOut)
|
| 347 |
async def upload_profile_picture(file: UploadFile = File(...), current_user: dict = Depends(get_current_user)):
|
| 348 |
try:
|
| 349 |
+
# Optimize the image: resize to 512x512, convert to JPEG, and apply eco quality for compression
|
| 350 |
+
result = cloudinary.uploader.upload(
|
| 351 |
+
file.file,
|
| 352 |
+
transformation=[{
|
| 353 |
+
"width": 512,
|
| 354 |
+
"height": 512,
|
| 355 |
+
"crop": "limit",
|
| 356 |
+
"quality": "auto:eco",
|
| 357 |
+
"fetch_format": "jpg"
|
| 358 |
+
}]
|
| 359 |
+
)
|
| 360 |
except Exception as e:
|
| 361 |
raise HTTPException(status_code=400, detail=f"Image upload failed: {str(e)}")
|
| 362 |
image_url = result.get("secure_url")
|