Skip to content

Commit

Permalink
fix: update formparser to new Starlette version (#3542)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauyon authored Feb 8, 2023
1 parent 30f8366 commit 9a6dc93
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bentoml/_internal/utils/formparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import uuid
import typing as t
from typing import TYPE_CHECKING
from tempfile import SpooledTemporaryFile

import multipart.multipart as multipart
from starlette.requests import Request
Expand Down Expand Up @@ -33,6 +34,9 @@ def user_safe_decode(src: bytes, codec: str) -> str:
return src.decode("latin-1")


MAX_FILE_SIZE = 1024 * 1024


class MultiPartParser:
"""
An modified version of starlette MultiPartParser.
Expand Down Expand Up @@ -151,7 +155,10 @@ async def parse(self) -> _ItemsBody:
)
if b"filename" in options:
filename = user_safe_decode(options[b"filename"], charset)
tempfile = SpooledTemporaryFile(max_size=MAX_FILE_SIZE)
multipart_file = UploadFile(
file=tempfile,
# size=0, # TODO: support size for starlette 0.24 onwards
filename=filename,
headers=Headers(raw=headers), # type: ignore (incomplete starlette types)
)
Expand Down

0 comments on commit 9a6dc93

Please sign in to comment.