简体   繁体   English

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

[英]Upload file to SharePoint drive using Microsoft Graph

We are trying to implement integration between a web application and SharePoint Online using Microsoft Graph rest API. 我们正在尝试使用Microsoft Graph rest API在Web应用程序和SharePoint Online之间实现集成。

Specifically, we need to upload a file to a specific SharePoint site's document library (drive), different than current user default drive. 具体来说,我们需要将文件上传到特定SharePoint网站的文档库(驱动器),而不是当前用户的默认驱动器。 We get the access token through Azure AD with access to all files. 我们通过Azure AD获取具有对所有文件的访问权限的访问令牌。

We can upload files into any drive using /v1.0/me/drive/... but not when we use another drive. 我们可以使用/v1.0/me/drive/...将文件上传到任何驱动器/v1.0/me/drive/...但是当我们使用其他驱动器时则不能。

For example: 例如:

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;

Both /v1.0 and /beta (in the case of SharePoint containing path) we are getting an error response of Not Implemented . /v1.0/beta (在SharePoint中包含路径的情况下)都收到Not Implemented的错误响应。

What could we be doing wrong? 我们可能做错了什么? Is it not yet working with Microsoft Graph (other than /me )? 它是否还不能使用Microsoft Graph( /me除外)?

In order to get all the files of a drive using v1.0, you would first need to get an access token (which I see you are already passed that), then get the 'drive-id' and use the following URL(note: its not 'drive' it is 'drives'): 为了使用v1.0获取驱动器的所有文件,您首先需要获取访问令牌(我看到您已经通过了该访问令牌),然后获取“ drive-id”并使用以下URL(注意:其不是“驱动器”,而是“驱动器”):

https://graph.microsoft.com/v1.0/drives/{drive-id}/root/children

To get the drive id, I made the following GET request using postman, this will list all the drives on the site and you will be able to get the ID of that drive: 要获取驱动器ID,我使用邮递员发出了以下GET请求,它将列出站点上的所有驱动器,您将能够获取该驱动器的ID:

https://graph.microsoft.com/v1.0/sites/{tenant}.sharepoint.com:{path-to-site(ie: /sites/HR)}:/drives

To answer your question regarding Uploading files, you will make a PUT request to the following URL: 要回答有关上传文件的问题,您将向以下URL发出PUT请求:

https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{folder-name}/{file-name.txt}:/content

You will need to set two required headers: 您将需要设置两个必需的标题:

  • Authorization 授权
  • Content-Type 内容类型

Next, you will pass the binary stream of the file into the body of the request. 接下来,您将把文件的二进制流传递到请求的主体中。

Other helpful items 其他有用的项目

Get all files inside of a folder: 获取文件夹中的所有文件:

https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{folder-name}:/children

Get content of users OneDrive: 获取用户OneDrive的内容:

https://graph.microsoft.com/v1.0/me/drive/root/children

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

:/content删除:通常,对我来说最好先获取sp库的driveId,然后再使用/v1.0/drive/{driveId}/在v1.0端点上工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Graph,上传到共享点驱动器:调用方未通过身份验证 - Microsoft Graph, upload to sharepoint drive: The caller is not authenticated Microsoft Graph Api 上传文件到 SharePoint - Microsoft Graph Api upload file to SharePoint 使用 Microsoft Graph 将 C# Asp.Net Core 中的文件上传到 Sharepoint/OneDrive,无需用户交互 - Upload a file in C# Asp.Net Core to Sharepoint/OneDrive using Microsoft Graph without user interaction 使用 Powershell 将文件上传到 Sharepoint Online (Microsoft 365)(选项 4 - 使用 Microsoft.SharePoint.Client.ClientContext) - Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 4 - Using Microsoft.SharePoint.Client.ClientContext) 使用 Powershell 将文件上传到 Sharepoint Online (Microsoft 365)(选项 2 - 使用 Microsoft.SharePoint.PowerShell) - Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 2 - Using Microsoft.SharePoint.PowerShell) 使用 Microsoft Graph API 下载 Sharepoint 文件未显示内容属性 - Downloading Sharepoint File using Microsoft Graph API not showing content attribute 使用“sourcedoc”ID从Microsoft Graph API下载SharePoint文件 - Download SharePoint file from Microsoft Graph API using “sourcedoc” ID 使用 Microsoft Graph SDK for java 将带有元数据的大文件上传到 SharePoint - Uploading large file to SharePoint with metadata using Microsoft Graph SDK for java 使用 Microsoft Graph 在线上传文件到 SharePoint API - Uploading a File to SharePoint Online using Microsoft Graph API 使用 Microsoft Graph 从 sharepoint 列表访问文件 - Access File from sharepoint list using Microsoft Graph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM