Skip to content

Commit d520e15

Browse files
authored
[Storage] Fix file upload with Oauth issue (#24291)
* Fix issue #24289 * Respect the actualy bytes number read from file stream.
1 parent b27b819 commit d520e15

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed upload file with OAuth authentication issue [#24289]
22+
- `Set-AzStorageFileContent`
2123

2224
## Version 6.1.2
2325
* Fixed parser logic when downloading blob from managed disk account with Sas Uri and bearer token on Linux and MacOS

src/Storage/Storage/File/Cmdlet/SetAzureStorageFileContent.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,29 +239,27 @@ await DataMovementTransferHelper.DoTransfer(() =>
239239
using (FileStream stream = File.OpenRead(localFile.FullName))
240240
{
241241
byte[] buffer = null;
242-
long lastBlockSize = 0;
243-
for (long offset = 0; offset < fileSize; offset += blockSize)
242+
for (long offset = 0; offset < fileSize;)
244243
{
245-
long currentBlockSize = offset + blockSize < fileSize ? blockSize : fileSize - offset;
244+
long targetBlockSize = offset + blockSize < fileSize ? blockSize : fileSize - offset;
246245

247-
// Only need to create new buffer when chunk size change
248-
if (currentBlockSize != lastBlockSize)
249-
{
250-
buffer = new byte[currentBlockSize];
251-
lastBlockSize = currentBlockSize;
252-
}
253-
await stream.ReadAsync(buffer: buffer, offset: 0, count: (int)currentBlockSize);
246+
// create new buffer, the old buffer will be GC
247+
buffer = new byte[targetBlockSize];
248+
249+
int actualBlockSize = await stream.ReadAsync(buffer: buffer, offset: 0, count: (int)targetBlockSize);
254250
if (!fipsEnabled && hash != null)
255251
{
256-
hash.AppendData(buffer);
252+
hash.AppendData(buffer, 0, actualBlockSize);
257253
}
258254

259255
Task task = UploadFileRangAsync(fileClient,
260-
new HttpRange(offset, currentBlockSize),
261-
new MemoryStream(buffer),
256+
new HttpRange(offset, actualBlockSize),
257+
new MemoryStream(buffer, 0, actualBlockSize),
262258
progressHandler);
263259
runningTasks.Add(task);
264260

261+
offset += actualBlockSize;
262+
265263
// Check if any of upload range tasks are still busy
266264
if (runningTasks.Count >= maxWorkers)
267265
{

0 commit comments

Comments
 (0)