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

13 statements  

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

1from fastapi import FastAPI, File, UploadFile 1abcd

2from fastapi.responses import HTMLResponse 1abcd

3 

4app = FastAPI() 1abcd

5 

6 

7@app.post("/files/") 1abcd

8async def create_files(files: list[bytes] = File()): 1abcd

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

10 

11 

12@app.post("/uploadfiles/") 1abcd

13async def create_upload_files(files: list[UploadFile]): 1abcd

14 return {"filenames": [file.filename for file in files]} 1abcd

15 

16 

17@app.get("/") 1abcd

18async def main(): 1abcd

19 content = """ 1abcd

20<body> 

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

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

23<input type="submit"> 

24</form> 

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

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

27<input type="submit"> 

28</form> 

29</body> 

30 """ 

31 return HTMLResponse(content=content) 1abcd