Coverage for docs_src/request_files/tutorial002_an_py39.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from typing import Annotated 1abcd
3from fastapi import FastAPI, File, UploadFile 1abcd
4from fastapi.responses import HTMLResponse 1abcd
6app = FastAPI() 1abcd
9@app.post("/files/") 1abcd
10async def create_files(files: Annotated[list[bytes], File()]): 1abcd
11 return {"file_sizes": [len(file) for file in files]} 1abcd
14@app.post("/uploadfiles/") 1abcd
15async def create_upload_files(files: list[UploadFile]): 1abcd
16 return {"filenames": [file.filename for file in files]} 1abcd
19@app.get("/") 1abcd
20async def main(): 1abcd
21 content = """ 1abcd
22<body>
23<form action="/files/" enctype="multipart/form-data" method="post">
24<input name="files" type="file" multiple>
25<input type="submit">
26</form>
27<form action="/uploadfiles/" enctype="multipart/form-data" method="post">
28<input name="files" type="file" multiple>
29<input type="submit">
30</form>
31</body>
32 """
33 return HTMLResponse(content=content) 1abcd