Мне нужно загрузить несколько изображений в oneNote через «oneNote API», но я не знаю, как записать двоичный код в код.
Вот код в моем коде:
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await Auth.GetAuthToken(provider));
string imagePartName = "imageBlock1";
StringBuilder simpleHtml = new StringBuilder();
simpleHtml.Append("<html lang=\"zh-CN\">\n");
simpleHtml.Append("<head>\n");
simpleHtml.Append("<title>" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</title>\n");
simpleHtml.Append("<meta name=\"created\" content=\"" + DateTime.Now.ToString("o") + "\" />\n");
simpleHtml.Append("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n");
simpleHtml.Append("</head>\n");
simpleHtml.Append("<body data-absolute-enabled=\"true\" style=\"font-family:Microsoft YaHei;font-size:11pt\">\n");
simpleHtml.Append("<img src=\"name:"+ imagePartName + "\" alt=\"a cool image\" width=\"500\"/>");
simpleHtml.Append("</body>\n");
simpleHtml.Append("</html>");
var createMessage = new HttpRequestMessage(HttpMethod.Post, apiRoute + "/pages")
{
Content = new MultipartFormDataContent
{
{
new StringContent(simpleHtml.ToString(), Encoding.UTF8, "text/html"), "Presentation"
}, //Here is the HTML data
//How to add "binary" data here
}
};
response = await client.SendAsync(createMessage);
Жду ответа каждого!