Describe your issue here.
slackclient version: 2.0.1 and 2.1.0
python version: 3.6.7
OS version(s): OSX 10.14.1 and Ubuntu 16.04.5
Take any html file, upload with explicitly setting the filetype and check out the assigned filetype in response:
>>> web_client.files_upload(channels=channel, file='index.html', filetype='svg').data
{'ok': True,
'file': {'id': 'xxxxxxx',
'created': 1563466794,
'timestamp': 1563466794,
'name': 'test',
'title': 'test',
'mimetype': 'text/plain',
'filetype': 'html',
'pretty_type': 'HTML',
'user': 'xxxxxx',
'editable': False,
'size': 5148500,
'mode': 'hosted',
'is_external': False,
'external_type': '',
'is_public': False,
'public_url_shared': False,
'display_as_bot': False,
'username': '',
'url_private': 'https://files.slack.com/files-pri/xxxxxx-xxxxxxxx/test',
'url_private_download': 'https://files.slack.com/files-pri/xxxxxx-xxxxxxx/download/test',
'permalink': 'https://fafb.slack.com/files/xxxxxxx/xxxxx/test',
'permalink_public': 'https://slack-files.com/xxxxxx-xxxxxx-xxxxxxxxx',
'comments_count': 0,
'is_starred': False,
'shares': {'private': {'xxxxxxxx': [{'reply_users': [],
'reply_users_count': 0,
'reply_count': 0,
'ts': 'xxxxxxxxx'}]}},
'channels': [],
'groups': [],
'ims': ['xxxxxx'],
'has_rich_preview': False}}
File is forced into given file type.
No matter what is used as filetype, it will always (correctly) parse the file as a html file with mimetype text/plain.
The reason why I tried forcing a different file type in the first place is that the specific .html file I am uploading is renamed to index.html.txt file by Slack upon subsequent download and I was hoping that forcing a different filetype would stop this behaviour.
FWIW: the same happenswhen I upload just the content instead of a file:
with open('index.html', 'r') as f:
_ = web_client.files_upload(channels=channel, content=f.read(), filetype='svg', filename='test.svg')
I'm aware that this looks to be more of an upstream issue with the Slack API. Please feel free to point me elsewhere with this issue.
facing same issue..plz help me if u got any solution
Thanks
@schlegelp and @blacktig3r To specify custom file types you can create your own file object with the FormData class provided by aiohttp.
from aiohttp import FormData
with open("index.html", "rb") as f:
data = FormData()
data.add_field(
"file", f, filename="index.html", content_type="image/svg+xml"
)
web_client.files_upload(channels=channel, file=data)
Please let me know if you run into any additional trouble with this.
As Rodney answered this question, please allow me to close this issue. Feel free to reopen or write in if you have something further.
Most helpful comment
@schlegelp and @blacktig3r To specify custom file types you can create your own file object with the
FormDataclass provided by aiohttp.Please let me know if you run into any additional trouble with this.