Skip to content

Commit

Permalink
Update MemoryWebClient.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
westdavidr authored May 24, 2024
1 parent 29d5ad3 commit 74940fe
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions 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,18 +438,16 @@ private async Task<string> ImportInternalAsync(
// Add files to the form
for (int i = 0; i < uploadRequest.Files.Count; i++)
{
using Stream fileStream = uploadRequest.Files[i].FileContent;

if (fileStream.CanSeek && fileStream.Position > 0)
if (uploadRequest.Files[i].FileContent is { CanSeek: true, Position: > 0 })
{
fileStream.Seek(0, SeekOrigin.Begin);
uploadRequest.Files[i].FileContent.Seek(0, SeekOrigin.Begin);
}

string fileName = uploadRequest.Files[i].FileName;
byte[] bytes;
using (var binaryReader = new BinaryReader(fileStream))
using (var binaryReader = new BinaryReader(uploadRequest.Files[i].FileContent))
{
bytes = binaryReader.ReadBytes((int)fileStream.Length);
bytes = binaryReader.ReadBytes((int)uploadRequest.Files[i].FileContent.Length);
}

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

0 comments on commit 74940fe

Please sign in to comment.