slack files.Upload in node失败,返回invalid_arg_name

问题描述 投票:0回答:1

我正在尝试并且未能通过托管在故障上的节点机器人将文件从s3获取到松弛文件。

我正在克隆的故障项目使用公理来发出Web请求。我正在请求将s3文件读入字符串,然后获取内容并将其放入对files.upload的请求中。 Files.upload通过帖子获取表单数据。

我不完全清楚如何构造表单数据“file”参数来获取字符串,但以下内容返回“invalid_arg_name”错误。

  var Readable = require('stream').Readable;
  // ...

  const upload = new FormData();
  upload.append("channels", destinationChannel);
  const s = new Readable();
  s.push("example s3 file content string");
  s.push(null);
  upload.append("file", s); 

  const config = { 
    headers: {'Authorization': "Bearer " + myAccessToken},
    'Content-Type': 'multipart/form-data',
  };

  axios.post(`${apiUrl}/files.upload`, upload, config)
    .then((result) => { 
      console.log('uploaded file'); 
      console.log(result.data);
   }); 

文档还说它需要一个url编码的形式,但我不确定将采用什么结构,或者它是否将处理我想通过此方法发送的10千字节文件。

如果我们可以修复这个方法,那就太好了,但是如果有一个更简单的方法来将公共URL提供给slack的files.upload,我也会这样做。

node.js axios slack slack-api glitch-framework
1个回答
0
投票

我能够通过querystring使用url编码,即使使用3k行日志文件也可以使用它:

const upload = {
  channels: channel,
  content: "s3 file content",
};

console.log(upload);
const config = { 
  headers: { 'Authorization': "Bearer " + myAccessToken },
  'Content-Type': 'application/x-www-form-urlencoded' 
};
axios.post(`${apiUrl}/files.upload`, qs.stringify(upload), config)
  .then((result) => { 
    console.log('uploaded file'); 
  }).catch((err) => {
    console.log('err on files upload %0', err);
  });

我不确定它会破坏的大小,所以我很想让formdata以某种方式工作。

© www.soinside.com 2019 - 2024. All rights reserved.