pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
888 B
35 lines
888 B
from fastapi import FastAPI, File, UploadFile
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.post("/files/")
|
|
async def create_files(
|
|
files: list[bytes] = File(description="Multiple files as bytes"),
|
|
):
|
|
return {"file_sizes": [len(file) for file in files]}
|
|
|
|
|
|
@app.post("/uploadfiles/")
|
|
async def create_upload_files(
|
|
files: list[UploadFile] = File(description="Multiple files as UploadFile"),
|
|
):
|
|
return {"filenames": [file.filename for file in files]}
|
|
|
|
|
|
@app.get("/")
|
|
async def main():
|
|
content = """
|
|
<body>
|
|
<form action="/files/" enctype="multipart/form-data" method="post">
|
|
<input name="files" type="file" multiple>
|
|
<input type="submit">
|
|
</form>
|
|
<form action="/uploadfiles/" enctype="multipart/form-data" method="post">
|
|
<input name="files" type="file" multiple>
|
|
<input type="submit">
|
|
</form>
|
|
</body>
|
|
"""
|
|
return HTMLResponse(content=content)
|
|
|