ambikanair
ambikanair

Reputation: 4600

How to upload a file to a slack channel using a bot

I have a slack bot and the token starting with xoxb is used to upload a file to a channel.

I am using below format

curl -F token="${SLACK_TOKEN}" -F file=e2e.sh -F channel="${SLACK_CHANNEL}" -F  as_user=true https://slack.com/api/files.upload

This throws

{"ok":false,"error":"no_file_data"}

Upvotes: 2

Views: 1256

Answers (1)

Stefanos Chrs
Stefanos Chrs

Reputation: 2528

You are missing the @ in your file=e2e.sh argument to let curl know you want to transmit a file. The following should do the trick:

curl \
  -F token="${SLACK_TOKEN}" \
  -F [email protected] \
  -F channel="${SLACK_CHANNEL}" \
  -F as_user=true \
  https://slack.com/api/files.upload

p.s. Breaking a long curl into multiple lines can help you see things more clearly ;)

Upvotes: 3

Related Questions