我正在使用NodeJ尝试通过Jira Rest API将附件上传到Jira Issue。
api需要multipart / form-data,所以这就是我在Node中调用它的方式:
function uploadAttachments(supportFormData, callback) {
const url =
'https://somewhere.com/jira/rest/api/2/issue/' +
supportFormData.issueId +
'/attachments';
var options = {
url: url,
headers: {
Authorization: { user: username, password: password },
'X-Atlassian-Token': 'nocheck'
}
};
var r = request.post(options, function(err, res, body) {
if (err) {
console.error(err);
callback(false);
} else {
console.log('Upload successful! Server responded with:', body);
callback(false);
}
});
var form = r.form();
form.append('file', supportFormData.attachments[0].contents, {
filename: supportFormData.attachments[0].fileName,
contentType: supportFormData.attachments[0].contents
});
}
我收到的错误是:
org.apache.commons.fileupload.FileUploadException:标头部分 超过10240个字节(可能未正确终止)
“ supportFormData.attachments [0] .contents”的类型为缓冲区。
关于什么可能导致此错误的任何建议?
答案 0 :(得分:0)
如果它的基本身份验证更改选项对象为
let auth = new Buffer(`${username}:${password}`).toString('base64');
var options = {
url: url,
headers: {
Authorization: `Basic ${auth}`,
'X-Atlassian-Token': 'nocheck'
}
};
答案 1 :(得分:0)
我遇到了同样的问题,结果发现JIRA(或Java)要求\r\n
作为换行符。将\n
更改为\r\n
后,我的请求顺利通过。