【发布时间】:2020-01-28 18:25:55
【问题描述】:
我正在尝试通过 Slack API https://slack.com/api/files.upload 使用带有 axios 库的 Node 上传远程文件。
https://api.slack.com/methods/files.upload
async filesUpload(token, channel, content, filename) {
const form = new FormData()
form.append('token', token)
form.append('channels', channel)
form.append('content', content)
form.append('filename', filename)
form.append('filetype', 'auto')
const { data } = await axios.post(
'https://slack.com/api/files.upload',
form,
{
headers: form.getHeaders(),
}
)
}
// url is a publicly available remote jpg image
const { data } = await axios.get(url, {
responseType: 'blob',
})
filesUpload('XXXX', 'XXXXX', data, 'foo.jpg')
Slack API 说得很好,并将其内容(一些乱码)发布到频道,在响应中我得到纯文本文件类型:
...
mimetype: 'text/plain',
filetype: 'text',
...
我很确定我要发送的编码是什么,但我没有选择。我尝试使用responseType: 'blob'、responseType: 'arraybuffer' 下载文件,但没有成功。
请帮忙。
【问题讨论】: