Microsoft graph api 无法将新文件(<;4MB)上载到SharePoint(ms graph api)

Microsoft graph api 无法将新文件(<;4MB)上载到SharePoint(ms graph api),microsoft-graph-api,microsoft-graph-files,Microsoft Graph Api,Microsoft Graph Files,我正在尝试将从Outlook获取的附件上载到SharePoint文档库中的文件夹。 我正在遵循以下文件: fetch(`https://graph.microsoft.com/v1.0/sites/${siteId}/drive/items/${parentId}:/${attachment.name}:/content`,{ 方法:'放', 模式:“cors”, 标题:新标题({ 'Authorization':'Bearer${accesToken}`, “内容类型”:“文本/普通” })

我正在尝试将从Outlook获取的附件上载到SharePoint文档库中的文件夹。 我正在遵循以下文件:

fetch(`https://graph.microsoft.com/v1.0/sites/${siteId}/drive/items/${parentId}:/${attachment.name}:/content`,{
方法:'放',
模式:“cors”,
标题:新标题({
'Authorization':'Bearer${accesToken}`,
“内容类型”:“文本/普通”
}),
正文:attachment.contentBytes
})
我得到的只是代码错误:
-1,Microsoft.SharePoint.Client.InvalidClientQueryException

我尝试过将fetch请求的主体设置为一个简单的字符串,比如“helloworld”,以进行测试,但仍然得到相同的错误

有什么想法吗

提前Thx


[编辑] 我怀疑我没有建立正确的URL。 我没有找到参数的文档:

  • {item id}我假设这个id是文件夹的
    parentReference.siteId
    属性

是吗?

好的,在使用Microsoft Graph Explorer进行了一些测试之后,我发现将文件上载到文档库(与根文档库不同)中的SharePoint文件夹的最简单方法是使用端点将其作为驱动器处理:

/drives/{drive-id}/items/{parent-id}:/{filename}:/content
()

为了获得文档库的驱动器id,您可以在图形查询中附加odata参数$expand=drive like:

`https://graph.microsoft.com/v1.0/sites/${siteId}/lists?$expand=drive`
然后,与目标文档库的其他属性一起,您将找到“驱动器”对象,该对象包含与要上载文件的文档库关联的驱动器id。因此,您可以像这样发出PUT请求:


取回(`https://graph.microsoft.com/v1.0/drives/${libraryDriveId}/items/root://${folderDisplayName}/${nameOfFile}:/content`{
方法:'放',
模式:“cors”,
标题:新标题({
'Authorization':'Bearer${accesToken}`,
“内容类型”:“文本/普通”
}),
正文:二进制\u数据流\u
})。然后((响应)=>{
如果(!response.ok)返回response.json(),那么((json)=>{throw json});
返回response.json();
})。然后((json)=>{
//做任何事
}).catch((错误)=>{
控制台错误(err);
})
图书馆驾驶员

  • libraryDriveId
    来自
    https://graph.microsoft.com/v1.0/sites/${siteId}/lists?$expand=drive
    request
  • /root://${folderDisplayName}
    表示您在文档库中针对的文件夹位于“root:”(文档库的根目录)下,后跟要将文件上载到的文件夹的
    displayName
  • nameOfFile
    是要上载的文件名

你得到这份工作了吗?我总是得到错误
实体只允许使用JSON内容类型头进行写入。
是的。看看我自己的回答:)