Replies: 1 comment 3 replies
-
In starlette's case it is not. You can read more here https://www.starlette.io/requests/#Request%20Files
So this is more of a starlette thing than a FastAPI thing. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
When we use httpx to upload a file without a filename, FastAPI seems to give a unexpected response.
Now I realize that this is not a very common case, however it is possible and correct to upload a file omitting the name in the multipart form post request.
To reproduce consider the following code:
Unfortunately this results in the 422 response:
Where one would expect a 200 response with body:
as the
filename
property ofUploadFile
isNone
by default.Please correct me if I am wrong, but it seems like an edge case that FastAPI currently does not support.
It is a bit annoying, because in order to satisfy mypy we have to check that the
filename
is notNone
if we want to use it in our code, however we cannot currently test the case where it actually isNone
, because the input validation fails in a odd way.Not sure where to look when it comes to fixing this, but I would be willing to spend some time debugging this if someone can point me in the right direction.
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.109.2
Pydantic Version
2.8.2
Python Version
3.12.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions