【发布时间】:2021-01-08 21:18:51
【问题描述】:
我在向 jira 云请求添加问题附件时遇到了问题。它返回 200 但响应是一个空数组。
const formData = new FormData();
for(var i = 0; i < files.length; i++){
let file = files[i];
formData.append("file", file.content, file.name);
}
console.log(formData); // see below
let params = {
method: 'post',
url: `https://submissive.atlassian.net/rest/api/3/issue/${createKey}/attachments`,
data: formData.getBuffer(),
headers: {
Accept: "application/json",
'X-Atlassian-Token': 'no-check',
'Authorization': getAuthHeader(user, apiToken),
... formData.getHeaders()
}
};
console.log('params: ', params);
let response = await axios(params);
console.log(response);
console.log(response.data); // [] empty array
console.log('attachments added');
表单数据:
FormData {
_overheadLength: 143,
_valueLength: 2946927,
_valuesToMeasure: [],
writable: false,
readable: true,
dataSize: 0,
maxDataSize: 2097152,
pauseStreams: true,
_released: false,
_streams: [
'----------------------------470840621872458708605830\r\n' +
'Content-Disposition: form-data; name="file"\r\n' +
'Content-Type: application/octet-stream\r\n' +
'\r\n',
<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 01 2c 01 2c 00 00 ff e1 28 3a 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 06 00 03 00 00 00 01 00 02 ... 2946877 more bytes>,
[Function: bound ]
],
_currentStream: null,
_insideLoop: false,
_pendingNext: false,
_boundary: '--------------------------470840621872458708605830'
}
长度为0有问题吗?我尝试使用和不使用扩展方法添加格式数据,结果相同。我已经确认我可以使用我构建 API 凭据的帐户添加附件。文件名正确:'file'。我唯一的想法可能是我错误地使用了缓冲区,但上面的表单日志使它看起来正确。
【问题讨论】:
标签: node.js jira-rest-api