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 616787a commit bfaa53a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bentoml/_internal/utils/formparser.py
Expand Up @@ -178,6 +178,16 @@ async def parse(self) -> _ItemsBody:
return items


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

return res


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 +210,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 bfaa53a

Please sign in to comment.