[英]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.