使用 xhr2 为 jira rest 添加附件到工单 api
Add attachemet to a ticket using xhr2 for jira rest api
我正在尝试使用 Jira rest api 和 xhr2 使用 node.js 和 electron
将文件上传到票证
这是我的代码
var XMLHttpRequest = require('xhr2')
var xhr = new XMLHttpRequest();
const fs = require('fs');
const filePath = 'test2.txt';
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('file', fileStream, {knownLength: fileSizeInBytes});
xhr.open("POST", "https:/myInstance/rest/api/2/issue/ticketid/attachments", true);
xhr.setRequestHeader("Authorization" , "Basic "+ Buffer.from("user" + ":" + "token").toString("base64"));
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('X-Atlassian-Token','no-check');
xhr.send(form);
我收到以下错误:
unsupported send() data [object FormData]
我可以使用以下方法附加文件:
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post
例子
但是我想知道我之前的代码有什么问题
我试图将这些添加到 header:
xhr.setRequestHeader('processData', false);
xhr.setRequestHeader('contentType',false);
它没有帮助,我也尝试添加:
xhr.setRequestHeader("Content-type", "multipart/form-data");
也没用
问题出在xhr本身
在文档中提到:
The following standard features are not implemented.
FormData
Blob
file:// URIs
data: URIs
upload progress events
synchronous operation
Same-origin policy checks and CORS
cookie processing
我正在尝试使用 Jira rest api 和 xhr2 使用 node.js 和 electron
将文件上传到票证这是我的代码
var XMLHttpRequest = require('xhr2')
var xhr = new XMLHttpRequest();
const fs = require('fs');
const filePath = 'test2.txt';
const form = new FormData();
const stats = fs.statSync(filePath);
const fileSizeInBytes = stats.size;
const fileStream = fs.createReadStream(filePath);
form.append('file', fileStream, {knownLength: fileSizeInBytes});
xhr.open("POST", "https:/myInstance/rest/api/2/issue/ticketid/attachments", true);
xhr.setRequestHeader("Authorization" , "Basic "+ Buffer.from("user" + ":" + "token").toString("base64"));
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('X-Atlassian-Token','no-check');
xhr.send(form);
我收到以下错误:
unsupported send() data [object FormData]
我可以使用以下方法附加文件: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-attachments/#api-rest-api-3-issue-issueidorkey-attachments-post 例子
但是我想知道我之前的代码有什么问题
我试图将这些添加到 header:
xhr.setRequestHeader('processData', false);
xhr.setRequestHeader('contentType',false);
它没有帮助,我也尝试添加:
xhr.setRequestHeader("Content-type", "multipart/form-data");
也没用
问题出在xhr本身 在文档中提到:
The following standard features are not implemented.
FormData
Blob
file:// URIs
data: URIs
upload progress events
synchronous operation
Same-origin policy checks and CORS
cookie processing