Skip to content

Commit 5f800c1

Browse files
authored
Add full_file_info_required to files_upload_v2 method (#1282)
1 parent f47f5cc commit 5f800c1

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

integration_tests/web/test_files_upload_v2.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,50 @@ async def test_uploading_file_with_token_param_async(self):
190190
file=upload["file"]["id"],
191191
)
192192
self.assertIsNotNone(deletion)
193+
194+
def test_request_file_info_false(self):
195+
client = self.sync_client
196+
upload = client.files_upload_v2(
197+
channels=self.channel_id,
198+
title="Foo",
199+
filename="foo.txt",
200+
content="foo",
201+
)
202+
self.assertIsNotNone(upload)
203+
self.assertIsNotNone(upload.get("files")[0].get("id"))
204+
self.assertIsNotNone(upload.get("files")[0].get("name"))
205+
206+
upload = client.files_upload_v2(
207+
channels=self.channel_id,
208+
title="Foo",
209+
filename="foo.txt",
210+
content="foo",
211+
request_file_info=False,
212+
)
213+
self.assertIsNotNone(upload)
214+
self.assertIsNotNone(upload.get("files")[0].get("id"))
215+
self.assertIsNone(upload.get("files")[0].get("name"))
216+
217+
@async_test
218+
async def test_request_file_info_false_async(self):
219+
client = self.async_client
220+
upload = await client.files_upload_v2(
221+
channels=self.channel_id,
222+
title="Foo",
223+
filename="foo.txt",
224+
content="foo",
225+
)
226+
self.assertIsNotNone(upload)
227+
self.assertIsNotNone(upload.get("files")[0].get("id"))
228+
self.assertIsNotNone(upload.get("files")[0].get("name"))
229+
230+
upload = await client.files_upload_v2(
231+
channels=self.channel_id,
232+
title="Foo",
233+
filename="foo.txt",
234+
content="foo",
235+
request_file_info=False,
236+
)
237+
self.assertIsNotNone(upload)
238+
self.assertIsNotNone(upload.get("files")[0].get("id"))
239+
self.assertIsNone(upload.get("files")[0].get("name"))

slack_sdk/web/async_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,7 @@ async def files_upload_v2(
30153015
channel: Optional[str] = None,
30163016
initial_comment: Optional[str] = None,
30173017
thread_ts: Optional[str] = None,
3018+
request_file_info: bool = True,
30183019
**kwargs,
30193020
) -> AsyncSlackResponse:
30203021
"""This wrapper method provides an easy way to upload files using the following endpoints:
@@ -3113,11 +3114,12 @@ async def files_upload_v2(
31133114
thread_ts=thread_ts,
31143115
**kwargs,
31153116
)
3116-
await _attach_full_file_metadata_async(
3117-
client=self,
3118-
token_as_arg=kwargs.get("token"),
3119-
completion=completion,
3120-
)
3117+
if request_file_info is True:
3118+
await _attach_full_file_metadata_async(
3119+
client=self,
3120+
token_as_arg=kwargs.get("token"),
3121+
completion=completion,
3122+
)
31213123
return completion
31223124

31233125
async def files_getUploadURLExternal(

slack_sdk/web/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,7 @@ def files_upload_v2(
30063006
channel: Optional[str] = None,
30073007
initial_comment: Optional[str] = None,
30083008
thread_ts: Optional[str] = None,
3009+
request_file_info: bool = True,
30093010
**kwargs,
30103011
) -> SlackResponse:
30113012
"""This wrapper method provides an easy way to upload files using the following endpoints:
@@ -3104,11 +3105,12 @@ def files_upload_v2(
31043105
thread_ts=thread_ts,
31053106
**kwargs,
31063107
)
3107-
_attach_full_file_metadata(
3108-
client=self,
3109-
token_as_arg=kwargs.get("token"),
3110-
completion=completion,
3111-
)
3108+
if request_file_info is True:
3109+
_attach_full_file_metadata(
3110+
client=self,
3111+
token_as_arg=kwargs.get("token"),
3112+
completion=completion,
3113+
)
31123114
return completion
31133115

31143116
def files_getUploadURLExternal(

slack_sdk/web/legacy_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,7 @@ def files_upload_v2(
30173017
channel: Optional[str] = None,
30183018
initial_comment: Optional[str] = None,
30193019
thread_ts: Optional[str] = None,
3020+
request_file_info: bool = True,
30203021
**kwargs,
30213022
) -> Union[Future, SlackResponse]:
30223023
"""This wrapper method provides an easy way to upload files using the following endpoints:
@@ -3115,11 +3116,12 @@ def files_upload_v2(
31153116
thread_ts=thread_ts,
31163117
**kwargs,
31173118
)
3118-
_attach_full_file_metadata(
3119-
client=self,
3120-
token_as_arg=kwargs.get("token"),
3121-
completion=completion,
3122-
)
3119+
if request_file_info is True:
3120+
_attach_full_file_metadata(
3121+
client=self,
3122+
token_as_arg=kwargs.get("token"),
3123+
completion=completion,
3124+
)
31233125
return completion
31243126

31253127
def files_getUploadURLExternal(

0 commit comments

Comments
 (0)