showing results for - "slack file upload axios"
Lina
28 Nov 2017
1const fs = require("fs"); 
2const axios = require("axios");
3const FormData = require("form-data");
4
5
6const form = new FormData();
7
8form.append("token", 'token here');
9form.append("channels", channelId);
10form.append("file", fs.createReadStream(__dirname + "/aapl.png"), 'file name');
11
12try {
13  const res = await axios.post("https://slack.com/api/files.upload", form, {
14    headers: form.getHeaders(),
15  });
16} catch (err) {
17  throw new Error(err);
18}