1

In the documentation about Upload, these request options are listed:

PUT /me/drive/items/{parent-id}:/{filename}:/content
PUT /me/drive/root:/{parent-path}/{filename}:/content
PUT /me/drive/items/{parent-id}/children/{filename}/content
PUT /groups/<id>/drive/items/<parent-id>/children/<filename>/content

In the documentation about Resumable Uploads, Create an upload session show these options:

POST /me/drive/root:/{path-to-item}:/createUploadSession
POST /me/drive/items/{parent-item-id}:/{filename}:/createUploadSession

What if I have to upload to other (not 'me') drive? For example, the default shared library (https://mycompany.sharepoint.com/Shared%20Documents), which for any other porpoise besides uploading, the documentation says can be accessed like this:

/drives/{drive-id}/items/{item-id}

So, my question is: Is it possible to upload to "/Shared Documents"? If so, which is the right syntax for the PUT (small file) or POST (upload session)? Perhaps something similar to this? (I just made this up, and it doesn't work)

PUT /drives/{drive-id}/items/{parent-id}/{filename}:/content

or (in case of an upload session):

POST /drives/{drive-id}/items/{parent-item-id}:/{filename}:/createUploadSession

For example, in the Graph Explorer, the response for something like this:

/v1.0/drives/THEDRIVEID/items/THEFOLDERID:/whatever.jpg:/createUploadSession

was:

{
    "error": {
        "code": "invalidRequest",
        "message": "A valid path must be provided.",
        "innerError": {
            "request-id": "THERETURNEDID",
            "date": "THERETURNEDDATE"
        }
    }
}

EDIT: Because the company's root can also be accessed as /drive/root/, I also tried (with no luck, in both 1.0 and beta):

/drive/root:/whatever.jpg:/createUploadSession
/drive/root/whatever.jpg:/createUploadSession
horacioj
  • 687
  • 1
  • 8
  • 25

1 Answers1

0

This is possible, but you need the right app permissions to be able to read/create files outside of the user's OneDrive. Instead of requesting Files.ReadWrite, you would need to request Sites.ReadWrite.All and then use /v1.0/drive/root:/file.bin:/createUploadSession.

You can also use the SharePoint Sites API in Microsoft Graph to access team site document libraries (other than the root site). However, this API is still in the beta version and should not be used in production apps.

Ryan Gregg
  • 2,015
  • 13
  • 16
  • Nice, it works!. I'm just wondering, why this is not consistent with every other API feature (which supports requests like /drives/the_drive_id/...) – horacioj Nov 17 '16 at 15:46
  • It should work, but there's a bug in the handling of /drives/{drive_id} that prevents the path syntax from working. We're working on it. – Ryan Gregg Nov 17 '16 at 21:37
  • Ryan Gregg you are a genius and my hero :-) For a week now I am trying this but only you told me the /root:/${file.fileName}:/ trick. I did not find it on any graph documentation. All they give is "drive/items/{itemId}". go figure what {itemId} is! Thank you Much Much Much Much – Ofer Gal May 22 '21 at 18:21
  • Now that I got it working, I want more :-) . Do you know I can truck the progress of the chunks? I am using JS SDK 2.2.1 const task: LargeFileUploadTask = new MicrosoftGraph.LargeFileUploadTask(graphIds.client, fileObject, uploadSession, options); const response = await task.upload(); is it something in the options? Again Thanks – Ofer Gal May 22 '21 at 18:30