Created
September 20, 2016 23:14
-
-
Save donpark/2a121d0514fe3175c7b8e5dc7ade10e9 to your computer and use it in GitHub Desktop.
node-slack-sdk example showing how to upload a stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var url = require('url'); | |
var request = require('request'); | |
var WebClient = require('@slack/client').WebClient; | |
var token = process.env.SLACK_API_TOKEN || ''; | |
var web = new WebClient(token); | |
var fileUrl = 'http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4'; | |
var fileName = path.basename(url.parse(fileUrl).pathname); | |
var fileStream = request(fileUrl) | |
if (!fileStream) throw new Error('could not fetch stream'); | |
// File upload via file param | |
var streamOpts = { | |
file: fileStream | |
}; | |
web.files.upload(fileName, streamOpts, function handleStreamFileUpload(err, res) { | |
if (err) { | |
console.error(err); | |
} else { | |
console.log(res); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment