0

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.

Anshu
  • 1,277
  • 2
  • 13
  • 28
Aaron Dasani
  • 73
  • 1
  • 1
  • 9
  • Can you put console.log (response) for the first axios request?Are you certain that response.data.upload.token is being created? – Aleksandar Pavić Jun 28 '19 at 05:18
  • Yes it is. i am getting this: ``` data: { upload: { token: '217.ae99d8c17793c5fd7193af715c3e5252' } } }``` – Aaron Dasani Jun 28 '19 at 16:00
  • I have just tested your code, and it works. Are you certain that project Testing is existing and your user has permissions, in line url: '/projects/Testing/wiki/Wiki.json', Also wiki module should be enabled at that project. – Aleksandar Pavić Jul 01 '19 at 05:00
  • That is very weird. Yes the project is call Testing and my user have permission. The thing is the text is being sent to the wiki page except for the attachment file. – Aaron Dasani Jul 01 '19 at 22:47
  • Are you looking into Redmine's console logs? – Aleksandar Pavić Jul 02 '19 at 05:33
  • No, i am looking in my local console. However I got it working with Ruby, i just had to learn ruby. I'll keep this question open so other people can have further discussion about this. – Aaron Dasani Jul 02 '19 at 16:21

0 Answers0