FastAPI upload files

Sarit Ritwirune
May 21, 2024

--

Part 17: Request Files

from fastapi import File, UploadFile

@app.post("/files/")
async def create_file(file: bytes = File(...)):
return {"file": len(file)}

@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile):
return {"filename": file.filename}

--

--

Sarit Ritwirune

On the way to full stack cross-platform. Currently make living by data science.