I wrote a script that take in a document and convert it into a string and send it to redmine as a wiki page. THIS WORKED GREAT.
NOW, I am trying to attach a file to it and the wiki page is being created and uploaded with the expected text, however, the attach file is not being sent.
And the weird thing is, I am not getting an error saying it is not being sent. I am actually getting a 201 response for the post request of the attach file, which is good but I am not seeing the file attach in the wiki page.
I also receive the token when i post the attachment so i can use it to do a PUT request with both the wiki text and the attach file, so you can see why I am so confuse.
I will provide my code in the file. Any help would be much appreciated.
//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)
})
}
I am expecting the File to be attach to the wiki page, but only the wiki page is being created and the attach file is not there.