I'm working on a website where the frontend is done in React and the backend in Python with FastAPI. I made a form which takes a some data and sends it to the backend with axios. It looks like this
{
name='Jonathan',
aliases=["Johnny"],
birthdate='2-15-1980',
gender='male',
height=178
weight=90
nationalities=["American", "French"],
occupations=["Programmer", "Comedian"],
status='single',
images=[
{'attachment': FileList,
'location': 'Berlin',
'date': '10-14-2019'
}
]
}
However, when I submit it, FastAPI seems to remove the images from the form.
name='Jonathan',
aliases=["Johnny"],
birthdate='2-15-1980',
gender='male',
height=178
weight=90
nationalities=["American", "French"],
occupations=["Programmer", "Comedian"],
status='single',
images=[
{'attachment': {'0': {}}, 'location': 'Berlin', 'date': '10-14-2019'}
]
This is what the route currently looks like
@router.post("/register/user")
def register_user(user_data: UserCreate):
print(user_data)
I'm not entirely sure what's going on. I'm guessing it has something to do with how the data is send and its encryption. I'm at a dead end here. Thanks in advance.
Edit: This is what the UserCreate Schema looks like
class CharacterCreate(BaseModel):
name: str
aliases: list
birthdate: Optional[str]
gender: str
height: Optional[float]
weight: Optional[float]
nationalities: Optional[set[str]]
occupations: Optional[set[str]]
status: str
images: Optional[list]
FileListin your frontend code? I'm guessing what you see is what you actually submit, and thatFileListisn't serializable in the way you expect.FileListseems to be a buit-in JS object, not a custom object. In the request payload it only shows asimages=[object Object]Form(...)I need to accept each field individually and that would make the function have lots of parameters. Is there any way to accept the files as one parameter and the rest of the form as another?