Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/_bentoml_sdk/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ def decode(self, obj: bytes | t.BinaryIO | UploadFile | PurePath | str) -> t.Any

media_type: str | None = None

if isinstance(obj, PurePath):
return Path(obj)
if isinstance(obj, str):
body = obj.encode("utf-8")
filename = None
if isinstance(obj, PurePath):
return Path(obj)
if isinstance(obj, UploadFile):
elif isinstance(obj, UploadFile):
body = obj.file.read()
filename = obj.filename
media_type = obj.content_type
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/_bentoml_sdk/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ def test_file_schema_decode_with_path_separator_in_filename(tmp_path: Path):
assert result.exists()
assert result.read_bytes() == file_content
assert result.suffix == ".pdf"


def test_file_schema_decode_with_string_payload(tmp_path: Path):
file_content = "test content"

with patch(
"bentoml._internal.context.request_temp_dir", return_value=str(tmp_path)
):
result = FileSchema().decode(file_content)

assert isinstance(result, Path)
assert result.exists()
assert result.read_text() == file_content
Loading