首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Microsoft Graph将文件上载到SharePoint驱动器

使用Microsoft Graph将文件上载到SharePoint驱动器
EN

Stack Overflow用户
提问于 2016-12-22 22:28:17
回答 2查看 13.8K关注 0票数 9

我们正在尝试使用Microsoft Graph rest API实现web应用程序和SharePoint Online之间的集成。

具体地说,我们需要将文件上传到特定SharePoint站点的文档库(驱动器),而不是当前用户默认的驱动器。我们通过Azure AD获得访问令牌,可以访问所有文件。

我们可以使用/v1.0/me/drive/...将文件上传到任何驱动器,但当我们使用其他驱动器时则不能。

例如:

代码语言:javascript
复制
var response = client.PutAsync(graphResourceUrl +
    "/beta/sharepoint/sites/" + siteCollSiteId +
    "/lists/" + listId +
    "/drive/root/children/" + fileName + ":/content",
    new ByteArrayContent(fileBytes)).Result;

var response = client.PutAsync(graphResourceUrl +
    "/beta/drives/" + "/" + listId +
    "/items/" + siteCollSiteId + "/" + fileName + ":/content",
    new ByteArrayContent(fileBytes)).Result;

var response = client.PutAsync(graphResourceUrl +
    "/beta/drives/" + listId + "/" + fileName + ":/content",
    new ByteArrayContent(fileBytes)).Result;

无论是/v1.0还是/beta (在SharePoint包含路径的情况下),我们都得到了Not Implemented的错误响应。

我们会做错什么呢?它是不是还不能使用微软的Graph (除了/me)?

EN

回答 2

Stack Overflow用户

发布于 2017-10-07 05:20:34

为了使用v1.0获取驱动器的所有文件,您首先需要获取一个访问令牌(我看到您已经传递了该令牌),然后获取' drive -id‘并使用以下URL(注意:不是'drive’,而是'drives'):

代码语言:javascript
复制
https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children

为了获取驱动器id,我使用postman发出了以下get请求,这将列出站点上的所有驱动器,您将能够获取该驱动器的ID:

代码语言:javascript
复制
https://graph.microsoft.com/v1.0/sites/{tenant}.sharepoint.com:{path-to-site(ie: /sites/HR)}:/drives

要回答有关上传文件的问题,您需要向以下URL发出PUT请求:

代码语言:javascript
复制
https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{folder-name}/{file-name.txt}:/content

您将需要设置两个必需的标头:

  • Authorization
  • Content-Type

接下来,您将把文件的二进制流传递到请求的主体中。

其他有帮助的项目

获取文件夹中的所有文件:

代码语言:javascript
复制
https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{folder-name}:/children

获取用户OneDrive的内容:

代码语言:javascript
复制
https://graph.microsoft.com/v1.0/me/drive/root/children

参考:https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_put_content#example-upload-a-new-file

票数 12
EN

Stack Overflow用户

发布于 2016-12-28 19:03:10

:/content中删除驱动器通常我最好先获取sp库的驱动器,然后使用/ v1.0 / driveId /{driveId}在v1.0端点上工作

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41285403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档