[英]no_file_data error when using Slack API upload
I'm getting this error {"ok":false,"error":"no_file_data"} when I try to call the slack API to upload. 尝试调用Slack API进行上传时,出现此错误{“ ok”:false,“ error”:“ no_file_data”}。 I already have the specified file in ./log. 我已经在./log中有指定的文件。
robot.respond /upload (.*)/i, (res) ->
app_name = res.match[1]
request = require("request")
fs = require("fs")
channel_name = res.message.room
data = {
channels: channel_name,
filename: "#{app_name}.txt",
file: fs.createReadStream("./log/#{app_name}.txt"),
}
robot.http("https://slack.com/api/files.upload")
.headers(Authorization: 'Bearer slack-token', 'Content-Type': 'application/json')
.post(data) (err, httpRes, body) ->
if err
res.send "#{err}"
return
res.send "#{body}"
This does not work, because the API method files.upload
does not support the content type application/json
posts. 这不起作用,因为API方法files.upload
不支持内容类型application/json
帖子。
For your case you need to post as multipart/form-data
, with one part containing the file data and one part containing the API parameters including the token. 对于您的情况,您需要以multipart/form-data
发布,其中一部分包含文件数据,另一部分包含API参数(包括令牌)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.