Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(multipart): support multipart file inputs to non-file descriptors #3005

Merged
merged 1 commit into from Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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