Project

General

Profile

RE: Uploading file to a wiki page using curl with the Res... ยป ApiSnippet.js

Aaron Dasani, 2019-06-27 00:17

 

// I am using Axios
// TO install it use this command: npm install axios

//a path to a picture in my computer
var picture = "../image1.png";

creatingWikiPage_AttachedFile(picture)

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, ![](image1.png) and other files.",
"uploads": [
{ "token": response.data.upload.token, "filename": "image1.png", "content-type": "image/png" }
]
}

}

})
.then(response => {
console.log("Put Document-------->>>>")
console.log(response);
})
.catch(error => {
console.log(error.response)
})

})
.catch(function (error) {
console.log(error.message)
})

}


    (1-1/1)