简体   繁体   English

如何使用文件夹路径和 Microsoft Graph API 1.0 上传文件

[英]How to upload files using folder path and Microsoft Graph API 1.0

I am working on a script to upload files to a folder using Microsoft Graph API 1.0.我正在编写一个脚本以使用 Microsoft Graph API 1.0 将文件上传到文件夹。 I am trying to make it so the user running the script can copy and paste the path of a sharepoint/onedrive folder.我正在尝试这样做,以便运行脚本的用户可以复制和粘贴 sharepoint/onedrive 文件夹的路径。 I of course want to use the path as a destination for the files to be uploaded too.我当然也想将路径用作要上传的文件的目的地。 So far I cannot find a way to get this to work.到目前为止,我找不到一种方法来让它工作。

Path example: https://example.sharepoint.com/sites/TheSite/Shared%20Documents/User路径示例: https://example.sharepoint.com/sites/TheSite/Shared%20Documents/User

API Reference: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0 API 参考: https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0

I have tried making GET calls to the API using the path, part of the path, and every variation of the hostname, and path.我尝试使用路径、部分路径以及主机名和路径的每个变体对 API 进行 GET 调用。 I am using the Python Requests library, and authentication is not an issue.我正在使用 Python 请求库,身份验证不是问题。

Errors received:收到的错误:

 "error": {
    "code": "itemNotFound",
    "message": "The resource could not be found."

and

  "error": {
    "code": "invalidRequest",
    "message": "Invalid hostname for this tenancy",

When we are using the storage path.当我们使用存储路径时。 we have to choose complete path for calling.whether it is Azure blob container or Sharepoint or Drive.我们必须选择完整的调用路径。它是 Azure blob 容器还是 Sharepoint 或驱动器。

Please refer below link for uploading data请参考以下链接上传数据

https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http https://medium.com/@rahul.metangale/upload-a-file-to-sharepoint-using-azure-graph-api-9deacce57449 https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http https://medium.com/@rahul.metangale/upload-a -file-to-sharepoint-using-azure-graph-api-9deacce57449

steps to upload:上传步骤:

1)Generate Token - using tenant, client id, client secret 1)生成令牌 - 使用租户、客户端 ID、客户端密码

2)Get drive id GET https://graph.microsoft.com/v1.0/drives 2)获取驱动器ID GET https://graph.microsoft.com/v1.0/drives

3)Upload Document Smaller than 4MB: PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content Header: “Authorization”: “Bearer Body: binary (select binary option in body in postman) Upload a file using select file option file-name: is file name along with extension example: test.txt 3)上传小于4MB的文件:PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content Header: “授权”:“承载正文:二进制(在邮递员的正文中选择二进制选项)使用select文件选项上传文件文件名:是文件名和扩展名示例:test.txt

4)Upload Document Greater than 4MB GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession Header: “Authorization”: “Bearer This will return upload url Upload Document PUT Header: “Authorization”: “Bearer Body: binary (select binary option in body in postman) 4)Upload Document Greater than 4MB: Header: “Authorization”: “Bearer 4)上传大于4MB的文档 GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession Header: “Authorization”: “Bearer This will return upload url Upload Document PUT Header: “Authorization”: “Bearer Body: binary (select binary option in body in postman) 4)Upload Document Greater than 4MB: Header: “Authorization”: “Bearer

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

相关问题 Microsoft Graph Api 在文件夹中上传大文件 - Microsoft Graph Api Upload Large File in a folder 使用 Microsoft Graph API 获取文件夹中的所有文件 - Get all Files in a folder using Microsoft Graph API 如何使用 java sdk 和 microsoft graph API 从 Microsoft 团队获取/下载上传的文件 - How to get/download the uploaded files form Microsoft team using java sdk with microsoft graph API 如何使用 sharepoint API 或 Microsoft Graph 从 sharepoint 站点上的文件夹请求文件内容? - How to request file content from a folder on a sharepoint site using sharepoint API or Microsoft Graph? Microsoft Graph API - 如何将附件上传到列表项 - Microsoft Graph API - How to upload attachments to a list item 尝试使用Microsoft Graph api搜索Sharepoint文件 - Trying to search Sharepoint files using Microsoft Graph api 如何使用 Microsoft Graph API 和 Graph Client 添加 SharePoint 选项卡? - How to add a SharePoint tab using Microsoft Graph API and Graph Client? 将PDF上传到OneDrive Microsoft Graph Rest API - Upload PDF to OneDrive Microsoft Graph Rest API Microsoft Graph Api 上传文件到 SharePoint - Microsoft Graph Api upload file to SharePoint 使用 microsoft graph 在 Office 365 上创建上传 session 到 sharepoint 站点文件夹 - create upload session to sharepoint site folder on Office 365 using microsoft graph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM