Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix file upload with Oauth issue #24291

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixed upload file with OAuth authentication issue [#24289]
- `Set-AzStorageFileContent`

## Version 6.1.2
* Fixed parser logic when downloading blob from managed disk account with Sas Uri and bearer token on Linux and MacOS
Expand Down
24 changes: 11 additions & 13 deletions src/Storage/Storage/File/Cmdlet/SetAzureStorageFileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,27 @@ await DataMovementTransferHelper.DoTransfer(() =>
using (FileStream stream = File.OpenRead(localFile.FullName))
{
byte[] buffer = null;
long lastBlockSize = 0;
for (long offset = 0; offset < fileSize; offset += blockSize)
for (long offset = 0; offset < fileSize;)
{
long currentBlockSize = offset + blockSize < fileSize ? blockSize : fileSize - offset;
long targetBlockSize = offset + blockSize < fileSize ? blockSize : fileSize - offset;

// Only need to create new buffer when chunk size change
if (currentBlockSize != lastBlockSize)
{
buffer = new byte[currentBlockSize];
lastBlockSize = currentBlockSize;
}
await stream.ReadAsync(buffer: buffer, offset: 0, count: (int)currentBlockSize);
// create new buffer, the old buffer will be GC
buffer = new byte[targetBlockSize];

int actualBlockSize = await stream.ReadAsync(buffer: buffer, offset: 0, count: (int)targetBlockSize);
if (!fipsEnabled && hash != null)
{
hash.AppendData(buffer);
hash.AppendData(buffer, 0, actualBlockSize);
}

Task task = UploadFileRangAsync(fileClient,
new HttpRange(offset, currentBlockSize),
new MemoryStream(buffer),
new HttpRange(offset, actualBlockSize),
new MemoryStream(buffer, 0, actualBlockSize),
progressHandler);
runningTasks.Add(task);

offset += actualBlockSize;

// Check if any of upload range tasks are still busy
if (runningTasks.Count >= maxWorkers)
{
Expand Down