【问题标题】:no_file_data error when using Slack API upload使用 Slack API 上传时出现 no_file_data 错误
【发布时间】:2019-06-25 06:35:01
【问题描述】:

当我尝试调用 slack API 进行上传时,我收到此错误 {"ok":false,"error":"no_file_data"}。我已经在 ./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}"

【问题讨论】:

  • 感谢您添加 Slack 错误。将错误添加到您的第一个问题会更好,但不用担心。请删除您的第一个问题。

标签: coffeescript slack-api hubot


【解决方案1】:

这不起作用,因为 API 方法 files.upload 不支持内容类型 application/json 帖子。

对于您的情况,您需要以multipart/form-data 发布,其中一部分包含文件数据,另一部分包含 API 参数,包括令牌。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-25
    相关资源
    最近更新 更多