簡體   English   中英

使用Slack API上傳時出現no_file_data錯誤

[英]no_file_data error when using Slack API upload

嘗試調用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}"

這不起作用,因為API方法files.upload不支持內容類型application/json帖子。

對於您的情況,您需要以multipart/form-data發布,其中一部分包含文件數據,另一部分包含API參數(包括令牌)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM