【问题标题】:Trello create card attachment error: 'File too large' with 8kb imageTrello 创建卡片附件错误:\'File too large\' with 8kb image
【发布时间】:2022-10-06 03:11:38
【问题描述】:

尝试将 Trello 的 Create card attachment 与 8kb PNG 文件一起使用,我得到一个 \'File too large\' 错误作为回报。

代码示例:

    const image = await sharp(
      \"path/qrcode.png\"
    )
      .resize(200, 200)
      .webp({ quality: 20 })
      .toFormat(\"png\")
      .toBuffer();

    // * CREATE NEW CARD WITH LIST ID
    await axios
      .post(
        `https://api.trello.com/1/cards?idList={LISTKEYHERE}&key=${TRELLO_KEY}&token=${TRELLO_TOKEN}`,
        {
          name: \"Create new card\",
          pos: \"top\",
        }
      )
      .then((res) => {
        const id: any = res.data.id;

        axios.post(
          `https://api.trello.com/1/cards/${id}/attachments?key=${TRELLO_KEY}&token=${TRELLO_TOKEN}`,
          { file: image }
        );
      });

我从其他伤害中了解到,免费版本的 trello 允许上传 10mb 的附件,8kb 的图像应该远低于该限制。

我还测试了 trello 板的前端是否允许手动附加图像,相同的文件在 UI 端可以正常工作。

注意:我没有单独调用创建附件,还尝试了创建卡片(文件源)的初始调用的键值参数。同样的错误。

    标签: node.js image trello


    【解决方案1】:

    正如我们已经在 Trello 支持票上讨论过的那样,请让我在这里分享一个 nodejs 代码示例,以使用 fetch API 将图像上传到 Trello 卡:

    import fetch from 'node-fetch';
    import FormData from 'form-data';
    import fs from 'fs';
    
    const TRELLO_KEY = "TRELLO_KEY_HERE"
    const TRELLO_TOKEN = "TRELLO_TOKEN_HERE"
    const CARD_ID = "CARD_ID_HERE"
    
    const form = new FormData();
    form.append('file', fs.createReadStream('qrc.png')); //set here the filename
    
    fetch(`https://api.trello.com/1/cards/${CARD_ID}/attachments?key=${TRELLO_KEY}&token=${TRELLO_TOKEN}`, {
      method: 'POST',
      headers: {
        'Accept': 'application/json'
      },
      body: form
    })
      .then(response => {
        console.log(
          `Response: ${response.status} ${response.statusText}`
        );
        return response.text();
      })
      .then(text => console.log(text))
      .catch(err => console.error(err));
    

    【讨论】:

      猜你喜欢
      • 2021-12-18
      • 2020-10-20
      • 2014-10-30
      • 2012-09-08
      • 2021-12-25
      • 2020-07-18
      • 2013-12-07
      • 2015-03-29
      • 1970-01-01
      相关资源
      最近更新 更多