forked from slackapi/node-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload-a-file.js
More file actions
35 lines (25 loc) · 739 Bytes
/
upload-a-file.js
File metadata and controls
35 lines (25 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Example for creating and working with the Slack Web API.
*/
/* eslint no-console:0 */
/* eslint vars-on-top:0 */
var fs = require('fs');
var WebClient = require('@slack/client').WebClient;
var token = process.env.SLACK_API_TOKEN || '';
var web = new WebClient(token);
var filePath = '...';
var fileName = 'test_file.csv';
// File upload via content param
var contentOpts = {
content: fs.readFileSync(filePath)
};
web.files.upload(fileName, contentOpts, function handleContentFileUpload(err, res) {
console.log(res);
});
// File upload via file param
var streamOpts = {
file: fs.createReadStream(filePath)
};
web.files.upload(fileName, streamOpts, function handleStreamFileUpload(err, res) {
console.log(res);
});