0
votes

I have been trying to do a file upload to a channel using the graph Api. I can successful do an upload to my personal OneDrive, using the request https://graph.microsoft.com:443/v1.0/me/drive/root:/fileName:/content

However I am unable to upload to a channel. I have tried many combinations, but keep getting invalidRequest. Below are some of the request I have tried:

https://graph.microsoft.com:443/v1.0/groups/groupID/drive/items/channelID:/iconfinder_13_3561846_32.png:/content

https://graph.microsoft.com:443/v1.0/groups/groupID/drive/items/channelName:/iconfinder_13_3561846_32.png:/content

I have also tried inputting the channel ID in various ways:

xx:[email protected] [email protected] xx:xxxxxxxxxxxxxxxxxxxxxxxxx

1

1 Answers

1
votes

I found out what I was doing wrong. For anybody else who is having an issue, you have to get the folder id that backs the channel. Here is an example in C#.

// Get the folder of the channel (driveItem)
var item = await graphClient.Teams[teamID].Channels[channelID].FilesFolder
.Request().GetAsync();

// Do the put request
var uploadRequest = graphClient
                //.Me.Drive.Root
                .Groups[teamID]
                .Drive
                .Items[item.Id]
                .ItemWithPath(file.FileName)
                .Content.Request()
                .PutAsync<DriveItem>(file.OpenReadStream());