Uploads or creates a file. https://docs.slack.dev/reference/methods/files.upload
(
self,
*,
file: Optional[Union[str, bytes, IOBase]] = None,
content: Optional[Union[str, bytes]] = None,
filename: Optional[str] = None,
filetype: Optional[str] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
title: Optional[str] = None,
channels: Optional[Union[str, Sequence[str]]] = None,
**kwargs,
)
| 3974 | return self.api_call("files.sharedPublicURL", params=kwargs) |
| 3975 | |
| 3976 | def files_upload( |
| 3977 | self, |
| 3978 | *, |
| 3979 | file: Optional[Union[str, bytes, IOBase]] = None, |
| 3980 | content: Optional[Union[str, bytes]] = None, |
| 3981 | filename: Optional[str] = None, |
| 3982 | filetype: Optional[str] = None, |
| 3983 | initial_comment: Optional[str] = None, |
| 3984 | thread_ts: Optional[str] = None, |
| 3985 | title: Optional[str] = None, |
| 3986 | channels: Optional[Union[str, Sequence[str]]] = None, |
| 3987 | **kwargs, |
| 3988 | ) -> SlackResponse: |
| 3989 | """Uploads or creates a file. |
| 3990 | https://docs.slack.dev/reference/methods/files.upload |
| 3991 | """ |
| 3992 | _print_files_upload_v2_suggestion() |
| 3993 | |
| 3994 | if file is None and content is None: |
| 3995 | raise e.SlackRequestError("The file or content argument must be specified.") |
| 3996 | if file is not None and content is not None: |
| 3997 | raise e.SlackRequestError("You cannot specify both the file and the content argument.") |
| 3998 | |
| 3999 | if isinstance(channels, (list, tuple)): |
| 4000 | kwargs.update({"channels": ",".join(channels)}) |
| 4001 | else: |
| 4002 | kwargs.update({"channels": channels}) |
| 4003 | kwargs.update( |
| 4004 | { |
| 4005 | "filename": filename, |
| 4006 | "filetype": filetype, |
| 4007 | "initial_comment": initial_comment, |
| 4008 | "thread_ts": thread_ts, |
| 4009 | "title": title, |
| 4010 | } |
| 4011 | ) |
| 4012 | if file: |
| 4013 | if kwargs.get("filename") is None and isinstance(file, str): |
| 4014 | # use the local filename if filename is missing |
| 4015 | if kwargs.get("filename") is None: |
| 4016 | kwargs["filename"] = file.split(os.path.sep)[-1] |
| 4017 | return self.api_call("files.upload", files={"file": file}, data=kwargs) |
| 4018 | else: |
| 4019 | kwargs["content"] = content |
| 4020 | return self.api_call("files.upload", data=kwargs) |
| 4021 | |
| 4022 | def files_upload_v2( |
| 4023 | self, |