Coverage for docs_src/request_files/tutorial003_an.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from typing import List 1abcde

2 

3from fastapi import FastAPI, File, UploadFile 1abcde

4from fastapi.responses import HTMLResponse 1abcde

5from typing_extensions import Annotated 1abcde

6 

7app = FastAPI() 1abcde

8 

9 

10@app.post("/files/") 1abcde

11async def create_files( 1abcde

12 files: Annotated[List[bytes], File(description="Multiple files as bytes")], 

13): 

14 return {"file_sizes": [len(file) for file in files]} 1abcde

15 

16 

17@app.post("/uploadfiles/") 1abcde

18async def create_upload_files( 1abcde

19 files: Annotated[ 

20 List[UploadFile], File(description="Multiple files as UploadFile") 

21 ], 

22): 

23 return {"filenames": [file.filename for file in files]} 1abcde

24 

25 

26@app.get("/") 1abcde

27async def main(): 1abcde

28 content = """ 1abcde

29<body> 

30<form action="/files/" enctype="multipart/form-data" method="post"> 

31<input name="files" type="file" multiple> 

32<input type="submit"> 

33</form> 

34<form action="/uploadfiles/" enctype="multipart/form-data" method="post"> 

35<input name="files" type="file" multiple> 

36<input type="submit"> 

37</form> 

38</body> 

39 """ 

40 return HTMLResponse(content=content) 1abcde