Trello 卡附件未使用 node.js 中的 axios 上传

问题描述

我正在尝试使用 node.js 将笔记本电脑上已有的图像附件添加到 Trello 中的现有卡,但我不断收到来自 Trello API 413(负载太大)的 HTTP 错误响应。然而,文件只有 331kb,所以这似乎不太可能 - 更有可能我做错了什么!任何帮助都会很棒,因为这让我很生气!

const axios = require("axios")
const FormData = require('form-data');
const fs = require('fs')

const formData = new FormData()
formData.append("file",fs.readFileSync(readFilename))
formData.append("name",title)
formData.append("setCover",setCover)
formData.append("token",this.tokenId)
formData.append("key",this.apiKey)
//console.log("Headers:" +JSON.stringify(formData.getHeaders(),null,2))
//console.log("Body:" +JSON.stringify(formData.getBuffer().toString(),2))
let urlToPost = "https://api.trello.com/1/cards/"+cardId+"/attachments";

try {
    let response = await axios.post(urlToPost,formData.getBuffer(),formData.getHeaders())
    console.log("response:" +JSON.stringify(response,2))
} catch (error) {
    console.log("error:" +JSON.stringify(error,2))
}

来自回复

  _header: 'POST /1/cards/60546bb89ca22420d5d4ecdf/attachments HTTP/1.1\r\n' +
    'Accept: application/json,text/plain,*/*\r\n' +
    'Content-Type: application/x-www-form-urlencoded\r\n' +
    'User-Agent: axios/0.21.1\r\n' +
    'Content-Length: 343746\r\n' +
    'Host: api.trello.com\r\n' +
    'Connection: close\r\n' +
    '\r\n',response: {
  status: 413,statusText: 'Payload Too Large',headers: [Object],config: [Object],request: [ClientRequest],data: 'Error parsing body'
},

这对我来说似乎不是特别大 - 我在使用该应用程序时已将 10Mb 以上的文件直接上传到 trello。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)