Skip to content

Commit 29d5ad3

Browse files
author
David West
committed
Reset stream position before posting to server
1 parent 6805f73 commit 29d5ad3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

clients/dotnet/WebClient/MemoryWebClient.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,18 @@ private async Task<string> ImportInternalAsync(
438438
// Add files to the form
439439
for (int i = 0; i < uploadRequest.Files.Count; i++)
440440
{
441+
using Stream fileStream = uploadRequest.Files[i].FileContent;
442+
443+
if (fileStream.CanSeek && fileStream.Position > 0)
444+
{
445+
fileStream.Seek(0, SeekOrigin.Begin);
446+
}
447+
441448
string fileName = uploadRequest.Files[i].FileName;
442449
byte[] bytes;
443-
using (var binaryReader = new BinaryReader(uploadRequest.Files[i].FileContent))
450+
using (var binaryReader = new BinaryReader(fileStream))
444451
{
445-
bytes = binaryReader.ReadBytes((int)uploadRequest.Files[i].FileContent.Length);
452+
bytes = binaryReader.ReadBytes((int)fileStream.Length);
446453
}
447454

448455
var fileContent = new ByteArrayContent(bytes, 0, bytes.Length);

0 commit comments

Comments
 (0)