Search code examples
javascriptnode.jsslackslack-api

Issue with files.upload using Slack's Node SDK


I'm trying to upload a file through the Slack SDK but am having issues. Currently I'm getting a success with the code below:

const res = await client.files.upload({
  channel: 'CHANNEL',
  file: Buffer.from('hello'),
  filename: 'test.txt',
  filetype: 'text/plain',
});

The response looks something like:

{ ok: true,
  file:
   { id: 'FIDTM4IDM',
     created: 1568847491,
     timestamp: 1568847491,
     name: 'test.txt',
     title: 'test',
     mimetype: 'text/plain',
     filetype: 'text',
     pretty_type: 'Plain Text',
     ...
     ...
  }
}

However nothing is showing up in the channel when I check. I know things are configured correctly because I can post messages to the channel using the same configuration.

https://slack.dev/node-slack-sdk/web-api#upload-a-file


Solution

  • You spelled the property wrong. It's called channels not channel. So the API will ignore your channel property and the file is uploaded to Slack, but not shared in channel.

    Also make sure to use channel IDs only. Channel names are not supported.