Coverage for docs_src/request_files/tutorial003.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 List 1abcde
3from fastapi import FastAPI, File, UploadFile 1abcde
4from fastapi.responses import HTMLResponse 1abcde
6app = FastAPI() 1abcde
9@app.post("/files/") 1abcde
10async def create_files( 1abcde
11 files: List[bytes] = File(description="Multiple files as bytes"),
12):
13 return {"file_sizes": [len(file) for file in files]} 1abcde
16@app.post("/uploadfiles/") 1abcde
17async def create_upload_files( 1abcde
18 files: List[UploadFile] = File(description="Multiple files as UploadFile"),
19):
20 return {"filenames": [file.filename for file in files]} 1abcde
23@app.get("/") 1abcde
24async def main(): 1abcde
25 content = """ 1abcde
26<body>
27<form action="/files/" enctype="multipart/form-data" method="post">
28<input name="files" type="file" multiple>
29<input type="submit">
30</form>
31<form action="/uploadfiles/" enctype="multipart/form-data" method="post">
32<input name="files" type="file" multiple>
33<input type="submit">
34</form>
35</body>
36 """
37 return HTMLResponse(content=content) 1abcde