【发布时间】:2020-01-20 13:26:58
【问题描述】:
我正在尝试将从 Outlook 获取的附件上传到 SharePoint 文档库中的文件夹。 我正在关注文档: https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http#http-request-to-upload-a-new-file
fetch(`https://graph.microsoft.com/v1.0/sites/${siteId}/drive/items/${parentId}:/${attachment.name}:/content`, {
method: 'PUT',
mode: 'cors',
headers: new Headers({
'Authorization': `Bearer ${accesToken}`,
'Content-Type': 'text/plain'
}),
body: attachment.contentBytes
})
我得到的只是代码错误:-1, Microsoft.SharePoint.Client.InvalidClientQueryException
出于测试目的,我尝试将获取请求的主体设置为简单的字符串,例如“hello world”,但仍然得到相同的错误。
有什么想法吗?
提前谢谢
[编辑] 我怀疑我没有正确构建 URL。 我还没有找到参数的文档:
- {item-id} 我假设这个 ID 是文件夹的
parentReference.siteId属性。
是吗?
【问题讨论】:
-
你得到这份工作了吗?我总是收到错误
Entity only allows writes with a JSON Content-Type header. -
是的。看看我自己的回复:)
标签: microsoft-graph-api microsoft-graph-files