msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Uploading file to sharepoint is not working

Open lucas-garrido opened this issue 2 years ago • 2 comments

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 : image

lucas-garrido avatar Oct 13 '22 12:10 lucas-garrido

Thanks for raising this @lucas-garrido

Any chance you can confirm the version of the SDK you are using to perform this?

andrueastman avatar Oct 14 '22 07:10 andrueastman

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

lucas-garrido avatar Oct 14 '22 08:10 lucas-garrido

UPDATE: I've created a new empty sharepoint and its now working, so i think it was an authorization issue.

lucas-garrido avatar Oct 17 '22 15:10 lucas-garrido