-
Hi, I'm using I extended the User model to have an avatar/profile picture. I am able to update/add/etc from the admin panel provided by My class User(SQLAlchemyBaseUserTableUUID, Base):
name: str = Column(String)
avatar = Column(ImageField(upload_storage="avatar")) And I have a dedicated route to update the avatar: @router.patch('/users/me/profile-picture', response_model=UserRead, tags=["users"])
async def upload_profile_picture(
file: UploadFile = File(...),
user: User = Depends(current_active_user),
manager: UserManager = Depends(get_user_manager)
):
user = await manager.user_db.update(
user, {"avatar": file}
)
return user Is there a good way to validate the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can simply wrap your udpdate with a try/catch block https://github.com/jowilf/sqlalchemy-file/blob/fc91c904c483dffc4db5c30f7d77eb77b199f3c8/examples/fastapi/app.py#L117C1-L117C1 or handle the error globally https://fastapi.tiangolo.com/tutorial/handling-errors/#override-request-validation-exceptions |
Beta Was this translation helpful? Give feedback.
-
Well, now I feel silly as that sounds like the obvious and elegant way to do it. Thanks! |
Beta Was this translation helpful? Give feedback.
You can simply wrap your udpdate with a try/catch block https://github.com/jowilf/sqlalchemy-file/blob/fc91c904c483dffc4db5c30f7d77eb77b199f3c8/examples/fastapi/app.py#L117C1-L117C1 or handle the error globally https://fastapi.tiangolo.com/tutorial/handling-errors/#override-request-validation-exceptions