Debian Codegraph @

docs/examples/request_data/request_data_9.py

raw
1 from typing import Dict
2
3 from litestar import Litestar, post
4 from litestar.datastructures import UploadFile
5 from litestar.params import MultipartBody
6
7
8 @post(path="/")
9 async def handle_file_upload(
10 data: MultipartBody[Dict[str, UploadFile]],
11 ) -> Dict[str, str]:
12 file_contents = {}
13 for name, file in data.items():
14 content = await file.read()
15 file_contents[file.filename] = len(content)
16
17 return file_contents
18
19
20 app = Litestar(route_handlers=[handle_file_upload])