Skip to content

Commit

Permalink
Support pathlike objects in upload util
Browse files Browse the repository at this point in the history
Also switch to inbuilt filename encode helper, since it accepts paths
  • Loading branch information
allen-pattern authored Feb 18, 2025
1 parent d6c206a commit 6d0dc4a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions slack_sdk/web/internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ def _to_v2_file_upload_item(upload_file: Dict[str, Any]) -> Dict[str, Optional[A
content = upload_file.get("content")
data: Optional[bytes] = None
if file is not None:
if isinstance(file, str): # filepath
with open(file.encode("utf-8", "ignore"), "rb") as readable:
if isinstance(file, (str, os.PathLike)): # filepath
with open(os.fsencode(file), "rb") as readable:
data = readable.read()
elif isinstance(file, bytes):
data = file
Expand Down

0 comments on commit 6d0dc4a

Please sign in to comment.