Skip to content

Commit 94cc04f

Browse files
committed
feat: support bytesio as child object of ipy.Files
1 parent 2751294 commit 94cc04f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

interactions/client/utils/serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def to_image_data(imagefile: Optional["UPLOADABLE_TYPE"]) -> Optional[str]:
146146
with open(str(imagefile), "rb") as image_buffer:
147147
image_data = image_buffer.read()
148148
case File():
149-
with imagefile.open_file() as image_buffer:
150-
image_data = image_buffer.read()
149+
data = imagefile.open_file()
150+
image_data = data.read() if hasattr(data, "read") else data
151151
case _:
152152
return imagefile
153153

interactions/models/discord/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def open_file(self) -> BinaryIO:
4040
A file-like BinaryIO object.
4141
4242
"""
43-
if isinstance(self.file, (IOBase, BinaryIO)):
43+
if isinstance(self.file, (IOBase, BinaryIO, bytes)):
4444
return self.file
4545
return open(str(self.file), "rb")
4646

0 commit comments

Comments
 (0)