【问题标题】:Download trello attachment nodejs下载 trello 附件 nodejs
【发布时间】:2018-10-08 22:25:39
【问题描述】:

美好的一天

任何人都有一个例子,关于如何使用 nodejs 从 trello 下载卡片附件?

如果你有任何想法,请与我分享。

问候, 马克

【问题讨论】:

    标签: javascript node.js trello


    【解决方案1】:

    对此我不确定,但可以通过简单搜索找到:

    https://github.com/adunkman/node-trello#fetching-card-data

    var Trello = require("node-trello");
    var t = new Trello("<your key>", "<token>");
    
    t.get("/1/members/me", function(err, data) {
     if (err) throw err;
     console.log(data);
    });
    
    // URL arguments are passed in as an object.
    t.get("/1/members/me", { cards: "open" }, function(err, data) {
     if (err) throw err;
      console.log(data);
     });
    

    【讨论】:

    • 谢谢你的回复,我有那个。但是这个例子将获取板/卡上的所有数据。想要从特定卡片中获取图片附件。
    【解决方案2】:

    这有效,结合使用 node-trello npm 库和一个简单的 HTTPS 请求。为您的 Trello API 添加您自己的 ENV_SECRET 和 ENV_TOKEN。 GET 请求将返回一个 JSON 对象列表,卡片上的每个附件对应 1 个,指定要使用的 indexOfAttachment 和要访问的卡片的 cardId。

    var secret = ENV_SECRET;
    var token = ENV_TOKEN;
    
    var https = require('https');
    var fs = require('fs');
    var t = require('node-trello');
    
    downloadAttachment = function () {
        t.get('1/cards/' + cardId + '/attachments', (err, attachmentData) => {
            if (!err) {
                var url = attachmentData[indexOfAttachment].url;
                var filename = url.split('/')[url.split('/').length - 1];
                console.log(filename);
                var dest = '.downloads/' + filename;
                var download = fs.createWriteStream(dest);
                https.get(url + '?key=' + secret + '&token=' + token, (res) => {
                    res.pipe(download);
                    download.on('finish', function () {
                        download.close((err) => {
                            if (!err) {
                                return false;
                            } else {
                                console.log(err);
                            }
                        });
                    }).on('error', (err) => {
                        fs.unlink(dest);
                    });
                });
            } else {
                console.log(err);
            }
        });
    };
    

    【讨论】:

      猜你喜欢
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多