How do I add pictures to a Wiki Page using the REST API.
Added by Aaron Dasani over 5 years ago
Alright,so i thought that uploading a picture to the wiki page using the rest api will let me write !picture_name!
in my test file and the picture will display. But is does NOT. Which does not make any sense.
I made a post and put request to my redmine server and i am receiving both the text and the attachment pictures, however when i write !picture_name!
the picture does not get display.
SO, How do we go about making a Wiki Page and be able to display pictures in the wiki page using the rest API.
Any help will appreciated. Thank you.
Replies (1)
RE: How do I add pictures to a Wiki Page using the REST API. - Added by Aaron Dasani over 5 years ago
Got is working my image conversion was wrong
i should have open the image with "rb" mode. i did not. i just read the file like this : File.read(file_url), which is not right.
i did that and it worked:
Ruby Code:
File.open(file, 'rb') do |f| <Do the post request here for the attachment> response = RestClient.post(upload_url, f, {:multipart => true, :content_type => 'application/octet-stream' }) token = JSON.parse(response)['upload']['token'] <if receive token, Do the put request > response = RestClient.put(wiki_url, { :attachments => { :attachment1 => { # the hash key gets thrown away - name doesn't matter :token => token, :filename => file_name, :description => file_description # optional } }, :wiki_page => { :text => file_content # wiki_text # original wiki text } }) end
Check Out Rest client in Ruby