From 6d0dc4aaef489889e0ba33224f9bc9df76fb0298 Mon Sep 17 00:00:00 2001 From: allen-pattern <117094633+allen-pattern@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:13:57 -0500 Subject: [PATCH] Support pathlike objects in upload util Also switch to inbuilt filename encode helper, since it accepts paths --- slack_sdk/web/internal_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slack_sdk/web/internal_utils.py b/slack_sdk/web/internal_utils.py index 6a87b914..53f6fc0f 100644 --- a/slack_sdk/web/internal_utils.py +++ b/slack_sdk/web/internal_utils.py @@ -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