Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Unable to upload to onedrive/sharepoint #2145

Closed
wrharper-AASP opened this issue Sep 25, 2023 · 5 comments
Closed

Bug: Unable to upload to onedrive/sharepoint #2145

wrharper-AASP opened this issue Sep 25, 2023 · 5 comments

Comments

@wrharper-AASP
Copy link

wrharper-AASP commented Sep 25, 2023

using Microsoft.Graph;
using Microsoft.Graph.Models;

GraphServiceClient gs = new(blahblah);
var drive = await gs.Users[""].Drive.PutAsync() is missing!

Microsoft Graph is version 5.28.0 via nuget...

Why can't we just use REST calls via HttpClient instead of this GraphServiceClient mess that is always out of date and never has everything working? REST calls you can make work no matter what. Relying on an object that never is updated when changes happen is bad practice.

2 answers are acceptable here:
1: fix it....
2: give a way to do REST instead of forcing everyone to use GraphServiceClient.

@wrharper-AASP
Copy link
Author

Proof that this should be possible, or your docs are out of date...
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http

@wrharper-AASP
Copy link
Author

more so, the documents on https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http only shows how to do plaintext instead of bytes array which is way more useful. Why not show byte array examples? that would work with anything.

@wrharper-AASP
Copy link
Author

It is actually worse than expected. Even the directions from the docs do not work in msgraph for creating an upload session via: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0

image

@wrharper-AASP
Copy link
Author

The old way using Microsoft.SharePoint.Client; also does not work and gives access denied errors.

using (var context = new ClientContext(SharePointBaseURL))
{
    //context.Credentials = new NetworkCredential()
    context.ExecutingWebRequest += (s, e) =>
    {
        e.WebRequestExecutor.RequestHeaders["Authorization"] =
            "Bearer " + token;
    };

I already have scope permission setup, i removed the old sharepoint permissions since it said access denied even with them:
image

@wrharper-AASP wrharper-AASP changed the title Unable to upload to drive: Constant bugs, please allow HttpClient instead of GraphServiceClient Bug: Unable to upload to onedrive/sharepoint Sep 25, 2023
@wrharper-AASP
Copy link
Author

I found a way to do this via a stream and trial/error with odata method.... still need to allow GraphServiceClient to do this:

HttpClient client = new();
client.DefaultRequestHeaders.Authorization = new("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new("application/json"));
using MemoryStream ms = new(bytes);
StreamContent streamContent = new(ms);
Console.WriteLine(await client.PutAsync("https://graph.microsoft.com/v1.0/users/USERIDGOESHERE/drive/items/root:/test.txt:/content", streamContent));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant