Skip to content

Commit

Permalink
fix(multipart): support multipart file inputs to non-file descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
sauyon committed Sep 15, 2022
1 parent ff7ebe7 commit c2201fa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bentoml/_internal/utils/formparser.py
Expand Up @@ -178,6 +178,13 @@ async def parse(self) -> _ItemsBody:
return items


async def file_body_to_message(f: UploadFile):
return {
"type": "http.request",
"body": await f.read(),
}


async def populate_multipart_requests(request: Request) -> t.Dict[str, Request]:
content_type_header = request.headers.get("Content-Type")
content_type, _ = multipart.parse_options_header(content_type_header)
Expand All @@ -200,6 +207,10 @@ async def populate_multipart_requests(request: Request) -> t.Dict[str, Request]:
req._form = FormData([(field_name, data)]) # type: ignore (using internal starlette APIs)
if isinstance(data, bytes):
req._body = data
else:
req._receive = ( # type: ignore (using internal starlette APIs)
file_body_to_message(data)
)
reqs[field_name] = req
return reqs

Expand Down

0 comments on commit c2201fa

Please sign in to comment.