A Chow
A Chow

Reputation: 61

Microsoft Graph: Uploading files to shared with me folder on OneDrive?

I was able to successfully upload to Shared Documents folder using this approach. But I am looking for a way to upload files to Shared WithMe folder on OneDrive.

Is it possible to upload to "/Shared WithMe" folder on OneDrive? If so, which is the right syntax for the PUT (small file) or POST (upload session)? I spent a lot of time to figure this out but no luck.

Any help would be greatly appreciated.

Upvotes: 2

Views: 1554

Answers (2)

Augusto Icaro
Augusto Icaro

Reputation: 673

Complementing what @Mark Scott answered:

First, I got the driveId and itemId from shared with me files URI response:

GET /me/drive/sharedWithMe

To use the shared URI to upload a file, I need to change it for contains the file name and : upload URI characters. So, my URI is:

PUT /drives/{driveid}/items/{itemid}:/FILE_NAME.EXTENSION:/content

With this is possible to upload a file to a folder that you know the Id. But you can go further! Also, it's possible to use the known folder Id as root and specify a path to upload your file. This is great because automatically create the folder in the path that you specify..`

PUT /drives/{driveid}/items/{itemid}:/FOLDER/CHILD FOLDER/FILE_NAME.EXTENSION:/content

In the end, this will upload your file in: KNOWN_FOLDER_ID_NAME/FOLDER/CHILD FOLDER/FILE_NAME.EXTENSION

Bonus tip: You can get the shared folder Id from onedrive web URL when you are in the folder. The URL is like this:

https://onedrive.live.com/?id=YOUR_FOLDER_ID&cid=DONT_USE_THIS

Upvotes: 1

Mark Scott
Mark Scott

Reputation: 226

I had success with this approach:

PUT /drives/{driveid}/items/{itemid}/content

I was able to retrieve the driveid and the itemid from the DriveItem entity. For a given DriveItem, the driveid is at DriveItem.RemoteItem.ParentReference.DriveId (ItemReference docs) and the itemid is at DriveItem.RemoteItem.Id (RemoteItem docs).

The Files.ReadWrite.All permission seems to be required.

This approach worked for me in the UWP C# Graph SDK.

Upvotes: 6

Related Questions