This wrapper method provides an easy way to upload files using the following endpoints: - step1: https://docs.slack.dev/reference/methods/files.getUploadURLExternal - step2: "https://files.slack.com/upload/v1/..." URLs returned from files.getUploadURLExternal API - step3:
(
self,
*,
# for sending a single file
filename: Optional[str] = None, # you can skip this only when sending along with content parameter
file: Optional[Union[str, bytes, IOBase, os.PathLike]] = None,
content: Optional[Union[str, bytes]] = None,
title: Optional[str] = None,
alt_txt: Optional[str] = None,
highlight_type: Optional[str] = None,
snippet_type: Optional[str] = None,
# To upload multiple files at a time
file_uploads: Optional[List[Dict[str, Any]]] = None,
channel: Optional[str] = None,
channels: Optional[List[str]] = None,
initial_comment: Optional[str] = None,
thread_ts: Optional[str] = None,
request_file_info: bool = True, # since v3.23, this flag is no longer necessary
**kwargs,
)
| 4030 | return await self.api_call("files.upload", data=kwargs) |
| 4031 | |
| 4032 | async def files_upload_v2( |
| 4033 | self, |
| 4034 | *, |
| 4035 | # for sending a single file |
| 4036 | filename: Optional[str] = None, # you can skip this only when sending along with content parameter |
| 4037 | file: Optional[Union[str, bytes, IOBase, os.PathLike]] = None, |
| 4038 | content: Optional[Union[str, bytes]] = None, |
| 4039 | title: Optional[str] = None, |
| 4040 | alt_txt: Optional[str] = None, |
| 4041 | highlight_type: Optional[str] = None, |
| 4042 | snippet_type: Optional[str] = None, |
| 4043 | # To upload multiple files at a time |
| 4044 | file_uploads: Optional[List[Dict[str, Any]]] = None, |
| 4045 | channel: Optional[str] = None, |
| 4046 | channels: Optional[List[str]] = None, |
| 4047 | initial_comment: Optional[str] = None, |
| 4048 | thread_ts: Optional[str] = None, |
| 4049 | request_file_info: bool = True, # since v3.23, this flag is no longer necessary |
| 4050 | **kwargs, |
| 4051 | ) -> AsyncSlackResponse: |
| 4052 | """This wrapper method provides an easy way to upload files using the following endpoints: |
| 4053 | |
| 4054 | - step1: https://docs.slack.dev/reference/methods/files.getUploadURLExternal |
| 4055 | |
| 4056 | - step2: "https://files.slack.com/upload/v1/..." URLs returned from files.getUploadURLExternal API |
| 4057 | |
| 4058 | - step3: https://docs.slack.dev/reference/methods/files.completeUploadExternal |
| 4059 | and https://docs.slack.dev/reference/methods/files.info |
| 4060 | |
| 4061 | """ |
| 4062 | if file is None and content is None and file_uploads is None: |
| 4063 | raise e.SlackRequestError("Any of file, content, and file_uploads must be specified.") |
| 4064 | if file is not None and content is not None: |
| 4065 | raise e.SlackRequestError("You cannot specify both the file and the content argument.") |
| 4066 | |
| 4067 | # deprecated arguments: |
| 4068 | filetype = kwargs.get("filetype") |
| 4069 | |
| 4070 | if filetype is not None: |
| 4071 | warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.") |
| 4072 | |
| 4073 | # step1: files.getUploadURLExternal per file |
| 4074 | files: List[Dict[str, Any]] = [] |
| 4075 | if file_uploads is not None: |
| 4076 | for f in file_uploads: |
| 4077 | files.append(_to_v2_file_upload_item(f)) |
| 4078 | else: |
| 4079 | f = _to_v2_file_upload_item( |
| 4080 | { |
| 4081 | "filename": filename, |
| 4082 | "file": file, |
| 4083 | "content": content, |
| 4084 | "title": title, |
| 4085 | "alt_txt": alt_txt, |
| 4086 | "highlight_type": highlight_type, |
| 4087 | "snippet_type": snippet_type, |
| 4088 | } |
| 4089 | ) |