2

我正在尝试使用 Nodejs 中的 Microsoft Bot 框架上传 Jira 票证的附件。

我使用下面的代码片段在 Jira 中调用附件 Api:

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

dotenv.config();

class attachmentAPI {
    constructor() {
    }
    async uploadJIRAImage(key) {


        let urlString = `https://{jira-site-name}.atlassian.net/rest/api/2/issue/${key}/attachments`;
        console.log(urlString);

        const credentials = process.env.JiraUsername + ":" + process.env.JiraPassword;
        const hash = Buffer.from(credentials).toString('base64');
        const Basic = 'Basic ' + hash;


        let formData = new FormData();
        //Here I want to upload image url from emulator
        **let stream = fs.createReadStream("Image.png");**
        formData.append('file', stream);
        let formHeaders = formData.getHeaders();

        let res = await axios.post(urlString, formData, {
            headers: {
            'Accept': 'application/json',
            'Authorization': Basic,
            'X-Atlassian-Token': 'nocheck',
            ...formHeaders
            }
        });

        console.log("Api-Result: ",res)
    }
        

}
exports.attachmentAPI = attachmentAPI;

这样我现在就可以上传图片了。因为它位于本地的同一文件夹中。但我想从模拟器上传一个图像 url,需要附加到 JIRA 票证上。

模拟器图片上传的内容是这样的格式:

{
name: 'SAP-Logo.png',
contentType: 'image/png',
contentUrl: 'http://localhost:12345/v3/attachments/1b864600-fe77-11eb-bc85-b3c9f4256d99/views/original' 
}

如何成功地将上述代码中的图像 URL/路径作为将图像附加到 Jira 票证的表单数据发送?

提前致谢。

4

0 回答 0