Skip to content

Commit

Permalink
migrate to files_upload_v2 in the readme (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeg authored Sep 16, 2023
1 parent 91c22ea commit f5b39e0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Here we also ensure that the response back from Slack is a successful one and th

#### Uploading files to Slack

We've changed the process for uploading files to Slack to be much easier and straight forward. You can now just include a path to the file directly in the API call and upload it that way. You can find the details on this api call [here][files.upload]
We've changed the process for uploading files to Slack to be much easier and straight forward. You can now just include a path to the file directly in the API call and upload it that way.

```python
import os
Expand All @@ -124,7 +124,7 @@ client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])

try:
filepath="./tmp.txt"
response = client.files_upload(channels='#random', file=filepath)
response = client.files_upload_v2(channel='C0123456789', file=filepath)
assert response["file"] # the uploaded file
except SlackApiError as e:
# You will get a SlackApiError if "ok" is False
Expand All @@ -133,6 +133,8 @@ except SlackApiError as e:
print(f"Got an error: {e.response['error']}")
```

More details on the `files_upload_v2` method can be found [here][files_upload_v2].

### Async usage

`AsyncWebClient` in this SDK requires [AIOHttp][aiohttp] under the hood for asynchronous requests.
Expand Down Expand Up @@ -292,6 +294,6 @@ helpful and collaborative way.
[pypi]: https://pypi.org/
[gh-issues]: https://github.com/slackapi/python-slack-sdk/issues
[slack-community]: https://slackcommunity.com/
[files.upload]: https://api.slack.com/methods/files.upload
[files_upload_v2]: https://github.com/slackapi/python-slack-sdk/releases/tag/v3.19.0
[aiohttp]: https://aiohttp.readthedocs.io/
[urllib]: https://docs.python.org/3/library/urllib.request.html

0 comments on commit f5b39e0

Please sign in to comment.