msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
Uploading file to sharepoint is not working
Hello 🤚 I'm trying to upload a document on sharepoint but this is not working. Im not having any error but the document doesn't upload. i have tried both ways
var result = await _graphServiceClient
.Sites[_configuration.GetSection("SharePoint:AAI").Value]
.Drive
.Root
.ItemWithPath("testfolder/test.jpg")
.Content
.Request()
.PutAsync<DriveItem>(stream);
var uploadProps = new DriveItemUploadableProperties
{
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "replace" }
}
};
var uploadSession = await _graphServiceClient
.Sites[_configuration.GetSection("SharePoint:AAI").Value]
.Drive
.Root
.ItemWithPath("testfolder/test.jpg")
.CreateUploadSession(uploadProps)
.Request()
.PostAsync();
var largeFileUpload = new LargeFileUploadTask<DriveItem>(uploadSession, stream, 320 * 1024);
var totalLength = stream.Length;
// Create a callback that is invoked after each slice is uploaded
IProgress<long> progress = new Progress<long>(prog =>
{
Console.WriteLine($"Uploaded {prog} bytes of {totalLength} bytes");
});
UploadResult<DriveItem> uploadResult = await largeFileUpload.UploadAsync(progress);
Console.WriteLine(uploadResult.UploadSucceeded ?
$"Upload complete, item ID: {uploadResult.ItemResponse.Id}" :
"Upload failed");
var result = uploadResult.ItemResponse;
logs :
Thanks for raising this @lucas-garrido
Any chance you can confirm the version of the SDK you are using to perform this?
Thanks for raising this @lucas-garrido
Any chance you can confirm the version of the SDK you are using to perform this?
sure i'm using the version 4.44.0
UPDATE: I've created a new empty sharepoint and its now working, so i think it was an authorization issue.