From 71930785a71b3165e98a2d12d18b1a284f9cdb32 Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Thu, 8 Feb 2024 23:13:32 +0800 Subject: [PATCH] Ensure the finishupload endpoint is always called --- .../Model/SharePoint/Core/Internal/FileCollection.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FileCollection.cs b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FileCollection.cs index fa4765ff76..22f882f237 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FileCollection.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/FileCollection.cs @@ -96,8 +96,10 @@ private static async Task ChunkedFileUpload(File newFile, Stream content, var buffer = new byte[chunkSizeBytes]; int bytesRead; - while ((bytesRead = content.Read(buffer, 0, buffer.Length)) > 0) + while (true) { + bytesRead = content.Read(buffer, 0, buffer.Length); + // A chunk can be returned smaller than the bytes requested. See https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.read?view=net-5.0&viewFallbackFrom=net-3.1#System_IO_Stream_Read_System_Byte___System_Int32_System_Int32_ // The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, // or zero (0) if the end of the stream has been reached. @@ -135,6 +137,8 @@ private static async Task ChunkedFileUpload(File newFile, Stream content, BinaryBody = chunk }; await newFile.RequestAsync(api, HttpMethod.Post).ConfigureAwait(false); + + break; } else {