Skip to content

Commit

Permalink
Reset stream position before posting to server (#509)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
westdavidr and David West authored May 24, 2024
1 parent 6805f73 commit b3ae5f3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clients/dotnet/WebClient/MemoryWebClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -438,6 +438,11 @@ private async Task<string> 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))
Expand Down

0 comments on commit b3ae5f3

Please sign in to comment.