MCPcopy Index your code
hub / github.com/slackapi/python-slack-sdk / files_upload_v2

Method files_upload_v2

slack_sdk/web/client.py:4022–4124  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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

Calls 7

_to_v2_file_upload_itemFunction · 0.85
getMethod · 0.45
appendMethod · 0.45
_upload_fileMethod · 0.45