问题
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:
- add the name: prefix in the img tag src.
- 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