#UploadFile handling

1 messages · Page 1 of 1 (latest)

dawn flicker
#

I'm not quite sure how to handle an UploadFile object. I'm using Literstar with Motor, and in Mongo I can store binary objects in the db. I would like to have a user profile with a profile picture field that stores an image. I defined the model in Pydantic as

class User(BaseModel):
    username: str
    password: str
    display_name: str
    profile_picture: UploadFile
    birthdate: date

Now, this works for a post route, where I receive multipart data from the frontend - but what about a get route where I fetch an object from the db and pass it to the frontend? Do I create a second model with UploadFile replaced with bytes?

pallid foxBOT
#
Notes for UploadFile handling
At your assistance

@dawn flicker

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

sly monolith
#

You'll need different models for how you receive / return data and what you store in the database

#

Your DB model should be the one that has the profile_picture as bytes, as that's how it's stored in the DB. Then the other models could "translate" from that