New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload a file #64
Comments
Have you found a workaround for that? |
I see that's merged. So can you paste sample code for upload? |
@jonathan-s It works when using the argument 'content' instead of 'file'. |
I tried to upload an image like this. It uploaded alright, but it uploaded as a text file. How do I upload an image? |
You should override the method 'do' of slackclient._slackrequest.SlackRequest, make it looks like this:
and you can upload an image like this:
|
@prongs oh, sorry. Only overrides the method 'do' of slackclient._slackrequest.SlackRequest is not enough,the method 'api_call' of slackclient._client.SlackClient should be overrided too. |
Can't someone put a pull request for this? I'd spent 3-4 hours on this last and couldn't get it right. |
Easy way. Change file _slackrequest.py to this
|
Thanks, it worked. Do you wanna post it as a pull request? If not, can I post it? |
I can but I don't know how On Sat, Apr 2, 2016, 16:56 Rajat Khandelwal notifications@github.com
|
Just fork the repo, make changes and push those in your fork. Then click on |
Has anyone tried doing this since this issue was closed? I'm getting some errors when trying to send a file. Looks like in the time between this was closed and python 2 & 3 has been included via six. The new out-of-the-box logic now tries to serialize the JSON file. |
@rgreasons looks like this is fixed by 5766321 but there hasn't been a PyPI release yet |
I still got the error with the 1.0.2 :-/ |
@SadE54 Yup. I confirmed still an issue with 1.0.2 as well |
@SadE54 I can confirm this as well in the latest pypi release. |
For those who're still experiencing this, Instead of following,
Try this:
For example, I successfully uploaded a plain text file through:
|
Heejune is just about right. In version 1.0.2 it expects 'file', NOT ''files'. So typing: |
Those of you still getting JSON serializable error, check if you aren't calling 'file.upload' instead of 'files.upload'. Pretty stupid, I know, but it took me a good one hour to realize this error. |
I cannot figure out how to upload a file. I am getting 200 and ok: True, but no success uploading the file to the channel. self.slack_client.api_call('files.upload', Using kwarg file and not files. Sending text messages works fine. Anyone with similar issues? EDIT: If I try to open any of the urls I get: The requested file could not be found. |
FWIW I'm using from slackclient import SlackClient
sc = SlackClient(SLACK_TOKEN)
sc.api_call(
'files.upload',
channels='#slacktesting',
as_user=True,
filename='pic.jpg',
file=open('puppy.jpg', 'rb'),
) @stianlp Is |
I tried with # and without, couldn't find out how to make it work, so I gave up. Used requests instead, and it's working perfectly: r = requests.post('https://slack.com/api/files.upload',
data={'token': self.bot_token, 'channels': [self.channel],
'title': 'Analysis Graph'},
files={'file': open(file_path, 'rb')}) Is anyone else have trouble, you can always just send a request like the code above. |
Yeah, that method in the api wrapper is broken.
*Jonathan Sundqvist*
Twitter <http://www.twitter.com/ecologythinking> | Linkedin
<http://se.linkedin.com/in/jonathansundqvist>
2017-10-26 9:16 GMT+02:00 Stian Lind Petlund <notifications@github.com>:
… I tried with # and without, couldn't find out how to make it work, so I
gave up.
Used requests instead, and it's working perfectly:
r = requests.post('https://slack.com/api/files.upload', data={'token':
self.bot_token, 'channels': [self.channel], 'title': 'Analysis Graph'},
files={'file': open(file_path, 'rb')})
Is anyone else have trouble, you can always just send a request like the
code above.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#64 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACBsEr9KIhQ3mwFngg0q1brXEdoF_Ho0ks5swDHfgaJpZM4HbggM>
.
|
also for me the only way it worked was by adding |
The solution given by @alexandraj777 works like a charm. |
Huh, from @tsando's and @nicolaskern's responses I'm starting to think the |
Perhaps others were not making the silly mistake I was, but I saw the same issue (uploaded files were always private) and fixed it. It turns out I had copied my code from a chat.message call. So, I was using "channel" instead of "channels" so I wasn't actually posting the file to a channel. Once I realized my error and used "channels" it worked perfectly and the file was public. I'll swallow my pride and admit my dumb mistake in the hopes that it might help someone else. |
Some clarifications that helped me:
|
Thank you @alexandraj777 it save my day |
Thanks @alexandraj777. To make that script work with bot just change
|
It says here: https://api.slack.com/methods/files.upload that files need to be uploaded via multipart/form-data, which it looks like the current client doesn't support.
If we moved to requests #54, it would make it easier to use their files argument for that.
The text was updated successfully, but these errors were encountered: