简体   繁体   中英

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. I am trying to make it so the user running the script can copy and paste the path of a sharepoint/onedrive folder. 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

API Reference: 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. I am using the Python Requests library, and authentication is not an issue.

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.

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

steps to upload:

1)Generate Token - using tenant, client id, client secret

2)Get drive 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM