'Microsoft.Graph.Core Code:accessDenied uploading file to One Drive API
I use the below code to upload the file to OneDrive API.
var uploadedFile = await requestBuilder
.ItemWithPath(fileName)
.Content
.Request()
.PutAsync<DriveItem>(fileStream);
When requestBuilder is one of the following:
requestBuilder = graphClient.Sites[ids.siteId].Drive.Root;
requestBuilder = graphClient.Sites[ids.siteId].Drive.Items[ids.folderId];
It fails with the error below:
When I use requestBuilder as the following, it works fine:
requestBuilder = graphClient.Me.Drive.Root;
This code works fine for my companies Azure setup, but when I've had a customer create their Azure App, and have checked that it matches my setup; they are getting the error above.
Any ideas on this?
Solution 1:[1]
Check the permissions. If you call the following endpoint
PUT /sites/{site-id}/drive/items/{item-id}/content
var uploadedFile = await graphClient.Sites[ids.siteId].Drive.Root
.ItemWithPath(fileName)
.Content
.Request()
.PutAsync<DriveItem>(fileStream);
Sites.ReadWrite.All
permission is required.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user2250152 |