0

I'm trying to upload a file to my Share Point online's document directory. I already successfully managed log on tokens and associated code. All I'm looking for is the actual Http Web request string I can use in MS Graph explorer. I can then translate that string to my needs. I get to this point in MS Graph explorer.... https://graph.microsoft.com/v1.0/sites/MyRootsharepointsite/drives/MydriveID

I also understand the content needs to be an array of bytes, I'm totally stuck on https:// portion...

BTW I can easily do this to my one-drive account, but the same pathing does not work for SPO (office 365).

PaulCr125
  • 13
  • 4

1 Answers1

0

PaulCr125

Based on the question you posted, my understanding is you want to use Microsoft Graph to upload a file to the SharePoint Online's document directory.If I misunderstood your question, please feel free let me know.

My initial suggestion is that you can try use this API: PUT https://graph.microsoft.com/v1.0/drives/{document directory's id}/root:/{Folder Name}/{File Name}:/content.

Based on my test, we can create a stream of the file into the body of the request. And the steps of the solution resemble the following:

  1. Get the document directory's id by the API below:

https://graph.microsoft.com/v1.0/drives

The part of the response like this:

{

     "createdDateTime": "2018-06-26T15:06:46Z",

     "description": "",

     "id": {the directory's id},

     "lastModifiedDateTime": "2018-08-14T05:29:44Z",

     "name": "Documents",

     "webUrl": "https://XX.sharepoint.com/Shared%20Documents",

     "driveType": "documentLibrary",
}
  1. Make a PUT request to the following URL:

https://graph.microsoft.com/v1.0/drives/{the directory's id}/root:/{Folder Name}/{File Name}:/content

Note: Before initiating this request, we should set two required headers:

1) Authorization
2) Content-Type

For more detail, we can refer to the content of 'Upload or replace the contents of a DriveItem' and the question on the StackOverflow.

Keen Jin
  • 1,060
  • 1
  • 6
  • 8
  • I appreciate the response and I'm still struggling I'm getting a "Only one path can be specified in the URL" error.... I have my main company root site then a team site. I'll continue to try different combinations. Cannot understand why its so difficult to document something like this. – PaulCr125 Aug 14 '18 at 15:58
  • Finally after 3 weeks of trying different things.... https://graph.microsoft.com/v1.0/sites/MyCorporateSite/drives/MyDriveID/root:/Folder/SubFolder/1.txt:/content = byte array – PaulCr125 Aug 14 '18 at 18:48
  • Did the solution I provided solve your problem? If so, could you please mark this as answer. – Keen Jin Aug 15 '18 at 03:26