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

Method files_upload_v2

slack_sdk/web/legacy_client.py:3957–4059  ·  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

3955 return self.api_call("files.upload", data=kwargs)
3956
3957 def files_upload_v2(
3958 self,
3959 *,
3960 # for sending a single file
3961 filename: Optional[str] = None, # you can skip this only when sending along with content parameter
3962 file: Optional[Union[str, bytes, IOBase, os.PathLike]] = None,
3963 content: Optional[Union[str, bytes]] = None,
3964 title: Optional[str] = None,
3965 alt_txt: Optional[str] = None,
3966 highlight_type: Optional[str] = None,
3967 snippet_type: Optional[str] = None,
3968 # To upload multiple files at a time
3969 file_uploads: Optional[List[Dict[str, Any]]] = None,
3970 channel: Optional[str] = None,
3971 channels: Optional[List[str]] = None,
3972 initial_comment: Optional[str] = None,
3973 thread_ts: Optional[str] = None,
3974 request_file_info: bool = True, # since v3.23, this flag is no longer necessary
3975 **kwargs,
3976 ) -> Union[Future, SlackResponse]:
3977 """This wrapper method provides an easy way to upload files using the following endpoints:
3978
3979 - step1: https://docs.slack.dev/reference/methods/files.getUploadURLExternal
3980
3981 - step2: "https://files.slack.com/upload/v1/..." URLs returned from files.getUploadURLExternal API
3982
3983 - step3: https://docs.slack.dev/reference/methods/files.completeUploadExternal
3984 and https://docs.slack.dev/reference/methods/files.info
3985
3986 """
3987 if file is None and content is None and file_uploads is None:
3988 raise e.SlackRequestError("Any of file, content, and file_uploads must be specified.")
3989 if file is not None and content is not None:
3990 raise e.SlackRequestError("You cannot specify both the file and the content argument.")
3991
3992 # deprecated arguments:
3993 filetype = kwargs.get("filetype")
3994
3995 if filetype is not None:
3996 warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
3997
3998 # step1: files.getUploadURLExternal per file
3999 files: List[Dict[str, Any]] = []
4000 if file_uploads is not None:
4001 for f in file_uploads:
4002 files.append(_to_v2_file_upload_item(f))
4003 else:
4004 f = _to_v2_file_upload_item(
4005 {
4006 "filename": filename,
4007 "file": file,
4008 "content": content,
4009 "title": title,
4010 "alt_txt": alt_txt,
4011 "highlight_type": highlight_type,
4012 "snippet_type": snippet_type,
4013 }
4014 )

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected