Skip to content

Commit 42440fe

Browse files
authored
[Storage] Fixed [#12592]: Fix download blob fail when related sub directory not exist. (#12617)
* [Storage] Fixed [#12592]: Fix download blob fail when related sub directory not exist. * Add test case
1 parent 424db97 commit 42440fe

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Storage/Storage.Management.Test/ScenarioTests/StorageDataPlaneTests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ function Test-Blob
245245
Assert-AreEqual $t.Error $null
246246
Assert-AreEqual (Get-FileHash -Path $localDestFile2 -Algorithm MD5).Hash (Get-FileHash -Path $localSrcFile -Algorithm MD5).Hash
247247

248+
# upload/download blob which name include "/"
249+
$blobNameWithFolder = "aa/bb/cc/dd.txt"
250+
$localFileNameWithFolder= "aa\bb\cc\dd.txt"
251+
Set-AzStorageBlobContent -File $localSrcFile -Container $containerName -Blob $blobNameWithFolder -Force -Context $storageContext
252+
Get-AzStorageBlobContent -Container $containerName -Blob $blobNameWithFolder -Destination . -Force -Context $storageContext
253+
Assert-AreEqual (Get-FileHash -Path $localFileNameWithFolder -Algorithm MD5).Hash (Get-FileHash -Path $localSrcFile -Algorithm MD5).Hash
254+
Remove-Item -Path "aa" -Force -Recurse
255+
Remove-AzStorageBlob -Container $containerName -Blob $blobNameWithFolder -Force -Context $storageContext
256+
248257
Remove-AzStorageBlob -Container $containerName -Blob $objectName2 -Force -Context $storageContext
249258
$blob = Get-AzStorageBlob -Container $containerName -Context $storageContext
250259
Assert-AreEqual $blob.Count 1

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* Supported blob query acceleration
2222
- `Get-AzStorageBlobQueryResult`
2323
- `New-AzStorageBlobQueryConfig`
24+
* Fixed [#12592]: Fix download blob fail when related sub directory not exist.
25+
- `Get-AzStorageBlobContent`
2426

2527
## Version 2.4.0
2628
* Supported create container/blob Sas token with new permission x,t

src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,23 @@ internal void GetBlobContent(CloudBlobContainer container, string blobName, stri
218218
throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName));
219219
}
220220

221-
string filePath = GetFullReceiveFilePath(fileName, blobName, null);
221+
// Don't need get File full path here, since will get file full path in GetBlobContent() with blob object.
222222

223223
ValidatePipelineCloudBlobContainer(container);
224224

225225
if (UseTrack2Sdk())
226226
{
227227
BlobContainerClient track2container = AzureStorageContainer.GetTrack2BlobContainerClient(container, Channel.StorageContext, ClientOptions);
228228
BlobBaseClient blobClient = track2container.GetBlobBaseClient(blobName);
229-
GetBlobContent(blobClient, filePath, true);
229+
GetBlobContent(blobClient, fileName, true);
230230
}
231231
else
232232
{
233233
AccessCondition accessCondition = null;
234234
BlobRequestOptions requestOptions = RequestOptions;
235235
CloudBlob blob = GetBlobReferenceFromServerWithContainer(Channel, container, blobName, accessCondition, requestOptions, OperationContext);
236236

237-
GetBlobContent(blob, filePath, true);
237+
GetBlobContent(blob, fileName, true);
238238
}
239239
}
240240

0 commit comments

Comments
 (0)