我需要使用patch
请求在OneNote页面之间复制图像。如何使用MS Graph API执行此操作?
发布于 2021-07-19 01:25:26
下面是TypeScript中的工作实现。图像只是嵌入在HTML中(不是Microsoft记录的插入图像的方式,但它工作得很好)。
const resourceUrl = "https://graph.microsoft.com/v1.0/users('someone@test.com')/onenote/resources/{resourceId}/$value";
const imageData = await downloadImage(client, resourceUrl);
const b64 = Buffer.from(imageData).toString("base64");
const htmlString = `<p>test image:</p><img width="30" src="data:image/jpeg;base64,${b64}" />`;
const patchData = {
target: "body",
action: "prepend",
content: htmlString,
};
await client
.api(`/me/onenote/pages/${testInsertPageId}/content`)
.patch([patchData]);
export async function downloadImage(
client: Client,
imgSrc: string,
): Promise<Uint8Array> {
const result: ReadableStream = await client.api(imgSrc).get();
const reader = result.getReader();
let data: Uint8Array = new Uint8Array();
let readResult = await reader.read();
while (!readResult.done) {
const value: Uint8Array = readResult.value;
const prevData = data;
data = new Uint8Array(data.length + value.length);
data.set(prevData);
data.set(value, prevData.length);
readResult = await reader.read();
}
return data;
}
https://stackoverflow.com/questions/68434256
复制相似问题