Replies: 5 comments 4 replies
-
Looks like it's still bugged - confirmed multiple file uploads does not work with pydantic2 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi! This works for me: from fastapi import FastAPI, UploadFile
app = FastAPI()
@app.post("/")
async def upload_attachments(attachment_files: list[UploadFile] = []):
file_list = []
print(attachment_files)
if attachment_files:
for f in attachment_files:
file_list.append(f.filename)
return {"file_list": file_list}
|
Beta Was this translation helpful? Give feedback.
2 replies
-
Still seems to be broken on |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
Despite the fact that these types look completely wrong, this does seem to work (using @app.post(
"/upload_files",
)
async def upload_files(
files: list[UploadFile | str] = File(None),
):
for file in files or []:
print("file: %r %r", file.filename, file.content_type)
contents = await file.read()
print("contents: %r", contents[:100])
return {"result": "ok"} Tested for:
Would still appreciate someone having a look at this as it'd be nice to do: files: Optional[list[UploadFile]] = None |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
FastAPI (v0.103.1) raises a list type error when multiple file uploads are specified as optional and Pydantic v2.3.0 is installed. With the Pydantic v2.3.0, the example code returns the following response:
However, downgrading to Pydantic v1.10.12 returns the correct response:
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.103.1
Pydantic Version
2.3.0
Python Version
3.10.9
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions