From b3ae5f35583d50a0424f05f676c663f45078e4f5 Mon Sep 17 00:00:00 2001 From: David West Date: Fri, 24 May 2024 09:29:29 -0700 Subject: [PATCH] Reset stream position before posting to server (#509) I am using the Kernel Memory project's MemoryWebClient to upload a stream to the server. The stream needs to be rewound before it is posted, but currently, this step seems to be missing, causing the server to receive an empty stream. When attempting to upload a stream using MemoryWebClient, the server receives an empty stream. It appears that the stream is not being rewound to its beginning before the upload, which results in the server not receiving the complete data as intended. ## High level description (Approach, Design) Reset uploaded stream in MemoryWebclient --------- Co-authored-by: David West --- clients/dotnet/WebClient/MemoryWebClient.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clients/dotnet/WebClient/MemoryWebClient.cs b/clients/dotnet/WebClient/MemoryWebClient.cs index 281f9b5cf..bfa480fde 100644 --- a/clients/dotnet/WebClient/MemoryWebClient.cs +++ b/clients/dotnet/WebClient/MemoryWebClient.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; @@ -438,6 +438,11 @@ private async Task ImportInternalAsync( // Add files to the form for (int i = 0; i < uploadRequest.Files.Count; i++) { + if (uploadRequest.Files[i].FileContent is { CanSeek: true, Position: > 0 }) + { + uploadRequest.Files[i].FileContent.Seek(0, SeekOrigin.Begin); + } + string fileName = uploadRequest.Files[i].FileName; byte[] bytes; using (var binaryReader = new BinaryReader(uploadRequest.Files[i].FileContent))