fastapi-master/docs_src/request_files/tutorial001_03_an_py39.py

18 lines
421 B
Python
Raw Normal View History

2024-08-24 12:41:47 +08:00
from typing import Annotated
from fastapi import FastAPI, File, UploadFile
app = FastAPI()
@app.post("/files/")
async def create_file(file: Annotated[bytes, File(description="A file read as bytes")]):
return {"file_size": len(file)}
@app.post("/uploadfile/")
async def create_upload_file(
file: Annotated[UploadFile, File(description="A file read as UploadFile")],
):
return {"filename": file.filename}