我编写了一个脚本,它接收一个文档并将其转换为一个字符串并将其作为一个 wiki 页面发送到 redmine。这很好用。
现在,我正在尝试将文件附加到它,并且正在创建 wiki 页面并使用预期的文本上传,但是,未发送附加文件。
奇怪的是,我没有收到错误说它没有被发送。实际上,我收到了对附件的发布请求的 201 响应,这很好,但我没有在 wiki 页面中看到文件附件。
当我发布附件时,我也收到了令牌,因此我可以使用它对 wiki 文本和附件进行 PUT 请求,所以你可以看到我为什么这么困惑。
我将在文件中提供我的代码。任何帮助将非常感激。
//a path to a txt file in my computer
var filePath = '../attached.txt'
fs.readFile(filePath,"utf8", (err, data) => {
if (err) { throw err; }
creatingWikiPage_AttachedFile(data)
console.log(data)
})
function creatingWikiPage_AttachedFile(file) {
axios({
method: 'post',
url: '<redmine_url>/uploads.json',
headers: {
'Content-Type': 'application/octet-stream'
},
params: { 'key': '<api_key>' },
data: file
})
.then(function (response) {
console.log(" POST attached Files---> ");
console.log(response)
axios({
method: 'put',
url: '<redmine_url>/projects/Testing/wiki/Wiki.json',
headers: { 'Content-Type': 'application/json' },
params: { 'key': '<api_key>' },
data: {
"wiki_page": {
"text": "This is a wiki page with images and other files.",
"uploads": [
{ "token": response.data.upload.token, "filename": "attached.txt", "content-type": "text/plain" }
]
}
}
})
.then(response => {
console.log("Put Document-------->>>>")
console.log(response);
})
.catch(error => {
console.log(error.response)
})
})
.catch(function (error) {
console.log(error.message)
})
}
我希望将文件附加到 wiki 页面,但仅创建 wiki 页面并且附件文件不存在。