Isaac_R
Isaac_R

Reputation: 63

how to change file_upload format in Slack webClient

I'm trying to upload a CSV file in slack as message, the following Code works to upload the file:

import slack 
client = slack.WebClient(token='SLACK_TOKEN')

response = client.files_upload(
           channels='#Random',
           filetype='csv',
           title='Sample Report',
           file='sample.csv')
assert response["ok"]

however, the file gets uploaded as Textedit format not as a CSV.

[![enter image description here][1]][1]

how can I upload the file as CSV, I thought the argument 'filetype' will define the file as CSV.

Thanks in advance.

****Update****

I was able to do what I was looking for by adding the argument 'filename'.

import slack 
client = slack.WebClient(token='SLACK_TOKEN')

response = client.files_upload(
           channels='#Random',
           filetype='csv',
           filename='sampleReport.csv',
           title='Sample Report',
           file='sample.csv')
assert response["ok"]

Upvotes: 1

Views: 1468

Answers (1)

Isaac_R
Isaac_R

Reputation: 63

After a research here https://api.slack.com/methods/files.upload

I did understand why the file was uploaded as .txt

There are 2 arguments filetype and filename. filetype provides an identifier while filename provides the file extension.

the correct code will be:

import slack 
client = slack.WebClient(token='SLACK_TOKEN')

response = client.files_upload(
          channels='#Random',
          filetype='csv',
          filename='sampleReport.csv',
          title='Sample Report',
          file='sample.csv')
assert response["ok"]

Upvotes: 1

Related Questions