Add support for declaring UploadFile parameters without explicit File() (#4469)

This commit is contained in:
Sebastián Ramírez
2022-01-23 20:14:13 +01:00
committed by GitHub
parent 59b1f353b3
commit 1bf55200a9
16 changed files with 1086 additions and 30 deletions

View File

@@ -0,0 +1,21 @@
from typing import Optional
from fastapi import FastAPI, File, UploadFile
app = FastAPI()
@app.post("/files/")
async def create_file(file: Optional[bytes] = File(None)):
if not file:
return {"message": "No file sent"}
else:
return {"file_size": len(file)}
@app.post("/uploadfile/")
async def create_upload_file(file: Optional[UploadFile] = None):
if not file:
return {"message": "No upload file sent"}
else:
return {"filename": file.filename}