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.dependencies import get_current_user
|
||||
|
||||
# Avatar upload directory
|
||||
UPLOAD_DIR = Path("uploads/avatars")
|
||||
# Avatar upload directory (absolute path to ensure consistency)
|
||||
UPLOAD_DIR = Path("/app/uploads/avatars")
|
||||
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
ALLOWED_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"}
|
||||
@ -134,6 +134,9 @@ async def upload_avatar(
|
||||
filename = f"{current_user.id}_{uuid.uuid4().hex}{ext}"
|
||||
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:
|
||||
f.write(content)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user