RE: Uploading file to a wiki page using curl with the Res... ยป ApiSnippet.js
1 |
|
---|---|
2 |
// I am using Axios
|
3 |
// TO install it use this command: npm install axios
|
4 |
|
5 |
//a path to a picture in my computer
|
6 |
var picture = "../image1.png"; |
7 |
|
8 |
creatingWikiPage_AttachedFile(picture) |
9 |
|
10 |
function creatingWikiPage_AttachedFile(file) { |
11 |
|
12 |
axios({ |
13 |
method: 'post', |
14 |
url: '<redmine_url>/uploads.json', |
15 |
headers: { |
16 |
'Content-Type': 'application/octet-stream' |
17 |
},
|
18 |
params: { 'key': '<api_key>' }, |
19 |
data: file |
20 |
})
|
21 |
.then(function (response) { |
22 |
console.log(" POST attached Files---> "); |
23 |
console.log(response) |
24 |
|
25 |
axios({ |
26 |
method: 'put', |
27 |
url: '<redmine_url>/projects/Testing/wiki/Wiki.json', |
28 |
headers: { 'Content-Type': 'application/json' }, |
29 |
params: { 'key': '<api_key>' }, |
30 |
data: { |
31 |
|
32 |
"wiki_page": { |
33 |
"text": "This is a wiki page with images, ![](image1.png) and other files.", |
34 |
"uploads": [ |
35 |
{ "token": response.data.upload.token, "filename": "image1.png", "content-type": "image/png" } |
36 |
]
|
37 |
}
|
38 |
|
39 |
}
|
40 |
|
41 |
})
|
42 |
.then(response => { |
43 |
console.log("Put Document-------->>>>") |
44 |
console.log(response); |
45 |
})
|
46 |
.catch(error => { |
47 |
console.log(error.response) |
48 |
})
|
49 |
|
50 |
})
|
51 |
.catch(function (error) { |
52 |
console.log(error.message) |
53 |
})
|
54 |
|
55 |
}
|
56 |
|
57 |
|