Get-AzureStorageBlob returns null
I am trying to get a blob from azure:
$name = "myfolder/20180223_064819[1].jpg"
$blob = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob -eq $null # is True
and the file is present in storage, in the location specified above, I can see it using the azure storage explorer. However $blob is $null rather than throwing an error which is what usually happens when no file is found. I have been accessing other files fine.
If I create another file myfile/201802230648191.jpg. In this code $blob2 returns an object (which is what you'd expect)
$name = "myfolder/201802230648191.jpg"
$blob2 = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob2 -eq $null # is False
I have tried url escaping the name but then it throws a not found exception. I have looked at the naming rules here: https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata but don't appear to be violating any.
So, my question is, why does $blob return null instead of the object?
And also, How can I get blobs with a name containing [ or ] ?
powershell azure-storage
add a comment |
I am trying to get a blob from azure:
$name = "myfolder/20180223_064819[1].jpg"
$blob = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob -eq $null # is True
and the file is present in storage, in the location specified above, I can see it using the azure storage explorer. However $blob is $null rather than throwing an error which is what usually happens when no file is found. I have been accessing other files fine.
If I create another file myfile/201802230648191.jpg. In this code $blob2 returns an object (which is what you'd expect)
$name = "myfolder/201802230648191.jpg"
$blob2 = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob2 -eq $null # is False
I have tried url escaping the name but then it throws a not found exception. I have looked at the naming rules here: https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata but don't appear to be violating any.
So, my question is, why does $blob return null instead of the object?
And also, How can I get blobs with a name containing [ or ] ?
powershell azure-storage
add a comment |
I am trying to get a blob from azure:
$name = "myfolder/20180223_064819[1].jpg"
$blob = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob -eq $null # is True
and the file is present in storage, in the location specified above, I can see it using the azure storage explorer. However $blob is $null rather than throwing an error which is what usually happens when no file is found. I have been accessing other files fine.
If I create another file myfile/201802230648191.jpg. In this code $blob2 returns an object (which is what you'd expect)
$name = "myfolder/201802230648191.jpg"
$blob2 = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob2 -eq $null # is False
I have tried url escaping the name but then it throws a not found exception. I have looked at the naming rules here: https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata but don't appear to be violating any.
So, my question is, why does $blob return null instead of the object?
And also, How can I get blobs with a name containing [ or ] ?
powershell azure-storage
I am trying to get a blob from azure:
$name = "myfolder/20180223_064819[1].jpg"
$blob = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob -eq $null # is True
and the file is present in storage, in the location specified above, I can see it using the azure storage explorer. However $blob is $null rather than throwing an error which is what usually happens when no file is found. I have been accessing other files fine.
If I create another file myfile/201802230648191.jpg. In this code $blob2 returns an object (which is what you'd expect)
$name = "myfolder/201802230648191.jpg"
$blob2 = Get-AzureStorageBlob -Container $container.Name -Context $context -Blob $name -ErrorAction Stop
$blob2 -eq $null # is False
I have tried url escaping the name but then it throws a not found exception. I have looked at the naming rules here: https://docs.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata but don't appear to be violating any.
So, my question is, why does $blob return null instead of the object?
And also, How can I get blobs with a name containing [ or ] ?
powershell azure-storage
powershell azure-storage
edited Nov 22 '18 at 14:47
johnstaveley
asked Nov 15 '18 at 11:34
johnstaveleyjohnstaveley
493521
493521
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I test your code and got the same result as you. Then I checked the Get-AzureStorageBlob
doc and I found it supports wildcard search even the support for Accept wildcard characters
is false.
Then I further tested the code. I changed the picture name to Snipaste_2018-11-02_13-56-321.png
without and still use the code, It worked. Here is the result. So the problem is because the in the $name
was recognized as wildcard characters.
So if you still insist your name, you could use -Prefix
instead of -Blob
. Here is my result.
If you still have questions, please let me know.
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
|
show 2 more comments
I have answer this question in: https://github.com/Azure/azure-powershell/issues/7848#issuecomment-439307333
Generally agree with George, use -prefix
should be work since -prefix
not support wildcard search. Anyway, this will also get other blob start with the blob name, like test/new11_22[1].jpgab
, to only get the matched blob, you can filter the blobs with a pipeline like:
PS C:WINDOWSsystem32>> Get-AzureStorageBlob -Container $containerName -Context $ctx -prefix test/new11_22[1].jpg | ? $_.Name -eq "test/new11_22[1].jpg"
Container Uri: https://***.blob.core.windows.net/***
Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted
---- -------- ------ ----------- ------------ ---------- ------------ ---------
test/new11_22[1].jpg BlockBlob 2097152 application/octet-stream 2018-11-16 07:29:19Z False
Actually the benavior of Get-AzureStorageBlob is aligned with other Powershell cmdlets like Get-Item:
like for file c:tempnew11_22[1].jpg
, following is the result.
PS C:WINDOWSsystem32> get-item c:tempnew11_22[1].jpg
PS C:WINDOWSsystem32> get-item c:tempnew11_22?1?.jpg
Directory: C:temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/19/2018 7:27 PM 2097152 new11_22[1].jpg
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318563%2fget-azurestorageblob-returns-null%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I test your code and got the same result as you. Then I checked the Get-AzureStorageBlob
doc and I found it supports wildcard search even the support for Accept wildcard characters
is false.
Then I further tested the code. I changed the picture name to Snipaste_2018-11-02_13-56-321.png
without and still use the code, It worked. Here is the result. So the problem is because the in the $name
was recognized as wildcard characters.
So if you still insist your name, you could use -Prefix
instead of -Blob
. Here is my result.
If you still have questions, please let me know.
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
|
show 2 more comments
I test your code and got the same result as you. Then I checked the Get-AzureStorageBlob
doc and I found it supports wildcard search even the support for Accept wildcard characters
is false.
Then I further tested the code. I changed the picture name to Snipaste_2018-11-02_13-56-321.png
without and still use the code, It worked. Here is the result. So the problem is because the in the $name
was recognized as wildcard characters.
So if you still insist your name, you could use -Prefix
instead of -Blob
. Here is my result.
If you still have questions, please let me know.
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
|
show 2 more comments
I test your code and got the same result as you. Then I checked the Get-AzureStorageBlob
doc and I found it supports wildcard search even the support for Accept wildcard characters
is false.
Then I further tested the code. I changed the picture name to Snipaste_2018-11-02_13-56-321.png
without and still use the code, It worked. Here is the result. So the problem is because the in the $name
was recognized as wildcard characters.
So if you still insist your name, you could use -Prefix
instead of -Blob
. Here is my result.
If you still have questions, please let me know.
I test your code and got the same result as you. Then I checked the Get-AzureStorageBlob
doc and I found it supports wildcard search even the support for Accept wildcard characters
is false.
Then I further tested the code. I changed the picture name to Snipaste_2018-11-02_13-56-321.png
without and still use the code, It worked. Here is the result. So the problem is because the in the $name
was recognized as wildcard characters.
So if you still insist your name, you could use -Prefix
instead of -Blob
. Here is my result.
If you still have questions, please let me know.
answered Nov 16 '18 at 6:18
George ChenGeorge Chen
1,304119
1,304119
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
|
show 2 more comments
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
@johnstaveley if my answer could help you, could you accept my answer.Thanks.
– George Chen
Nov 22 '18 at 2:13
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
Yes,you could search without suffix, however you could also search with it like my picture shows.
– George Chen
Nov 23 '18 at 1:01
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley and i tried to search files with same names but different suffix, it works.
– George Chen
Nov 23 '18 at 1:41
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
@johnstaveley you could just search file name abc.jpg or abc.png with prefix.
– George Chen
Nov 27 '18 at 8:21
|
show 2 more comments
I have answer this question in: https://github.com/Azure/azure-powershell/issues/7848#issuecomment-439307333
Generally agree with George, use -prefix
should be work since -prefix
not support wildcard search. Anyway, this will also get other blob start with the blob name, like test/new11_22[1].jpgab
, to only get the matched blob, you can filter the blobs with a pipeline like:
PS C:WINDOWSsystem32>> Get-AzureStorageBlob -Container $containerName -Context $ctx -prefix test/new11_22[1].jpg | ? $_.Name -eq "test/new11_22[1].jpg"
Container Uri: https://***.blob.core.windows.net/***
Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted
---- -------- ------ ----------- ------------ ---------- ------------ ---------
test/new11_22[1].jpg BlockBlob 2097152 application/octet-stream 2018-11-16 07:29:19Z False
Actually the benavior of Get-AzureStorageBlob is aligned with other Powershell cmdlets like Get-Item:
like for file c:tempnew11_22[1].jpg
, following is the result.
PS C:WINDOWSsystem32> get-item c:tempnew11_22[1].jpg
PS C:WINDOWSsystem32> get-item c:tempnew11_22?1?.jpg
Directory: C:temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/19/2018 7:27 PM 2097152 new11_22[1].jpg
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
add a comment |
I have answer this question in: https://github.com/Azure/azure-powershell/issues/7848#issuecomment-439307333
Generally agree with George, use -prefix
should be work since -prefix
not support wildcard search. Anyway, this will also get other blob start with the blob name, like test/new11_22[1].jpgab
, to only get the matched blob, you can filter the blobs with a pipeline like:
PS C:WINDOWSsystem32>> Get-AzureStorageBlob -Container $containerName -Context $ctx -prefix test/new11_22[1].jpg | ? $_.Name -eq "test/new11_22[1].jpg"
Container Uri: https://***.blob.core.windows.net/***
Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted
---- -------- ------ ----------- ------------ ---------- ------------ ---------
test/new11_22[1].jpg BlockBlob 2097152 application/octet-stream 2018-11-16 07:29:19Z False
Actually the benavior of Get-AzureStorageBlob is aligned with other Powershell cmdlets like Get-Item:
like for file c:tempnew11_22[1].jpg
, following is the result.
PS C:WINDOWSsystem32> get-item c:tempnew11_22[1].jpg
PS C:WINDOWSsystem32> get-item c:tempnew11_22?1?.jpg
Directory: C:temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/19/2018 7:27 PM 2097152 new11_22[1].jpg
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
add a comment |
I have answer this question in: https://github.com/Azure/azure-powershell/issues/7848#issuecomment-439307333
Generally agree with George, use -prefix
should be work since -prefix
not support wildcard search. Anyway, this will also get other blob start with the blob name, like test/new11_22[1].jpgab
, to only get the matched blob, you can filter the blobs with a pipeline like:
PS C:WINDOWSsystem32>> Get-AzureStorageBlob -Container $containerName -Context $ctx -prefix test/new11_22[1].jpg | ? $_.Name -eq "test/new11_22[1].jpg"
Container Uri: https://***.blob.core.windows.net/***
Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted
---- -------- ------ ----------- ------------ ---------- ------------ ---------
test/new11_22[1].jpg BlockBlob 2097152 application/octet-stream 2018-11-16 07:29:19Z False
Actually the benavior of Get-AzureStorageBlob is aligned with other Powershell cmdlets like Get-Item:
like for file c:tempnew11_22[1].jpg
, following is the result.
PS C:WINDOWSsystem32> get-item c:tempnew11_22[1].jpg
PS C:WINDOWSsystem32> get-item c:tempnew11_22?1?.jpg
Directory: C:temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/19/2018 7:27 PM 2097152 new11_22[1].jpg
I have answer this question in: https://github.com/Azure/azure-powershell/issues/7848#issuecomment-439307333
Generally agree with George, use -prefix
should be work since -prefix
not support wildcard search. Anyway, this will also get other blob start with the blob name, like test/new11_22[1].jpgab
, to only get the matched blob, you can filter the blobs with a pipeline like:
PS C:WINDOWSsystem32>> Get-AzureStorageBlob -Container $containerName -Context $ctx -prefix test/new11_22[1].jpg | ? $_.Name -eq "test/new11_22[1].jpg"
Container Uri: https://***.blob.core.windows.net/***
Name BlobType Length ContentType LastModified AccessTier SnapshotTime IsDeleted
---- -------- ------ ----------- ------------ ---------- ------------ ---------
test/new11_22[1].jpg BlockBlob 2097152 application/octet-stream 2018-11-16 07:29:19Z False
Actually the benavior of Get-AzureStorageBlob is aligned with other Powershell cmdlets like Get-Item:
like for file c:tempnew11_22[1].jpg
, following is the result.
PS C:WINDOWSsystem32> get-item c:tempnew11_22[1].jpg
PS C:WINDOWSsystem32> get-item c:tempnew11_22?1?.jpg
Directory: C:temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/19/2018 7:27 PM 2097152 new11_22[1].jpg
edited Nov 16 '18 at 8:41
answered Nov 16 '18 at 7:58
Wei Wei -MicrosoftWei Wei -Microsoft
31112
31112
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
add a comment |
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
But prefix searches for the first part of a file name e.g. -Prefix abc will match abc.jpg abc.png etc. How can I get files with a name containing [ or ] ?
– johnstaveley
Nov 22 '18 at 14:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318563%2fget-azurestorageblob-returns-null%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown