Inserting image into existing OneNote page via REST api not working

时间秒杀一切 提交于 2019-12-13 02:54:49

问题


I can insert an image when I create a new page but when I try to add an image into an existing page I end up with an image link but no image displayed.

Image link only

This is the request:

Content-Disposition: form-data; name="Commands"

{
'Target':'body', 
'Action' : 'append', 
'Content' : '<div data-id=testdiv1><div>Chat message with mike</div></div>'
},
{
'Target':'#testdiv1', 
'Action' : 'insert', 
'Content' : '<img src="image1"/>'
}

Content-Type: image/png
Content-Disposition: form-data; name="image1"

imagedata....

Hopefully someone can see what I'm doing wrong or point me at a sample (preferably UWP based but willing to look at anything).

Thanks for the help.


回答1:


The request above has 2 patch actions, first is appending a div to the body and the section action is inserting an image to the div that was just appended. Can you try the following instead?

Content-Disposition: form-data; name="Commands"

{
'Target':'body', 
'Action' : 'append', 
'Content' : '<div data-id=testdiv1>
              <div>Chat message with mike</div>
              <img src="name:image1"/>
             </div>'
}

Content-Type: image/png
Content-Disposition: form-data; name="image1"

imagedata....

The two changes are:

  1. add the name: prefix in the img tag src.
  2. you can combine both patch actions into one action.

Also don't forget the usual multipart gotchas like ensuring boundary is provided between each part etc... Our GitHub sample can be useful.



来源:https://stackoverflow.com/questions/37304373/inserting-image-into-existing-onenote-page-via-rest-api-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!