Replies: 2 comments 1 reply
-
for your question i updated your code it working very well just for two endpoints for you example you do not need more then 2 endpoints from fastapi import FastAPI,Query,status,HTTPException,Depends,File,UploadFile,Form
from typing import Annotated
app = FastAPI()
# for Individual files
@app.post("/uploadfile",status_code=status.HTTP_200_OK)
async def create_upload_file(file: UploadFile=File(...)):
return {"filename": file.filename,"filesize":len(file.file.read())}
# for multiple files
@app.post("/uploadfiles",status_code=status.HTTP_200_OK)
async def create_upload_files(files: list[UploadFile]=File(...)):
return {"filename": [file.filename for file in files],"filesize":[len(file.file.read()) for file in files]} i hope i answered you question. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for looking. I only added the four different versions for demonstration purposes to show that the bytes and UploadFile versions, defined exactly as they are in the docs, both work for the individual case but are both not working for the multiple files case. Your suggested changes for the {"detail":[{"type":"missing","loc":["body","files"],"msg":"Field required","input":null}]} |
Beta Was this translation helpful? Give feedback.
1 reply
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
curl -F '[email protected]' http://localhost:8000/file/
{"file_size":202725}
curl -F '[email protected]' http://localhost:8000/uploadfile/
{"filename":"test.pdf"}
curl -F 'files[][email protected]' http://localhost:8000/files/
{"detail":[{"type":"missing","loc":["body","files"],"msg":"Field required","input":null}]}
curl -F 'files[][email protected]' http://localhost:8000/uploadfiles/
{"detail":[{"type":"missing","loc":["body","files"],"msg":"Field required","input":null}]}
Operating System
macOS
Operating System Details
MacOS 13.5
FastAPI Version
0.111.0
Pydantic Version
2.7.0
Python Version
3.11.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions