Coverage for docs_src/request_files/tutorial003_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( 1abcd
11 files: Annotated[list[bytes], File(description="Multiple files as bytes")],
12):
13 return {"file_sizes": [len(file) for file in files]} 1abcd
16@app.post("/uploadfiles/") 1abcd
17async def create_upload_files( 1abcd
18 files: Annotated[
19 list[UploadFile], File(description="Multiple files as UploadFile")
20 ],
21):
22 return {"filenames": [file.filename for file in files]} 1abcd
25@app.get("/") 1abcd
26async def main(): 1abcd
27 content = """ 1abcd
28<body>
29<form action="/files/" enctype="multipart/form-data" method="post">
30<input name="files" type="file" multiple>
31<input type="submit">
32</form>
33<form action="/uploadfiles/" enctype="multipart/form-data" method="post">
34<input name="files" type="file" multiple>
35<input type="submit">
36</form>
37</body>
38 """
39 return HTMLResponse(content=content) 1abcd