fix: Ensure avatar upload directory uses an absolute path and is created before file writes.
This commit is contained in:
parent
605cbc3a8b
commit
c49e56b1e7
@ -13,8 +13,8 @@ from app.schemas.user import UserCreate, UserUpdate, UserResponse, Token
|
|||||||
from app.services.auth import get_password_hash, verify_password, create_access_token
|
from app.services.auth import get_password_hash, verify_password, create_access_token
|
||||||
from app.dependencies import get_current_user
|
from app.dependencies import get_current_user
|
||||||
|
|
||||||
# Avatar upload directory
|
# Avatar upload directory (absolute path to ensure consistency)
|
||||||
UPLOAD_DIR = Path("uploads/avatars")
|
UPLOAD_DIR = Path("/app/uploads/avatars")
|
||||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
ALLOWED_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"}
|
ALLOWED_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"}
|
||||||
@ -134,6 +134,9 @@ async def upload_avatar(
|
|||||||
filename = f"{current_user.id}_{uuid.uuid4().hex}{ext}"
|
filename = f"{current_user.id}_{uuid.uuid4().hex}{ext}"
|
||||||
file_path = UPLOAD_DIR / filename
|
file_path = UPLOAD_DIR / filename
|
||||||
|
|
||||||
|
# Ensure directory exists (may be missing after volume recreate)
|
||||||
|
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with open(file_path, "wb") as f:
|
with open(file_path, "wb") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user