清单Azure存储的Blob在公共容器匿名 [英] Listing Azure storage blobs in public container anonymously

查看:208
本文介绍了清单Azure存储的Blob在公共容器匿名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了微软的Azure PowerShell的模块来创建存储帐户内的Azure存储帐户和BLOB容器。我给自己定的BLOB容器可以公开访问,但现在我需要从一个匿名连接列出斑点。

我使用的是Windows管理框架核心5.0 2014年11月preVIEW与Azure的PowerShell模块,版本0.8.12。

下面是code,我用来创建存储帐户,BLOB容器,上传文件到容器。

  ###验证到微软Azure平台
$用户名='powershell@trevorsullivan.net';
$ AzureCredential = GET-凭证-Message输入您的Azure的密码。 -username $用户名;
附加AzureAccount -Credential $ AzureCredential;###选择适当的Azure订阅
$ SubscriptionName ='的Visual Studio旗舰版和MSDN';
选择-AzureSubscription -SubscriptionName $ SubscriptionName;###创建Azure存储帐户
$ StorageAccountName ='opsgility';
新AzureStorageAccount -StorageAccountName $ StorageAccountName;###创建Azure存储上下文
$ StorageKey = GET-AzureStorageKey -StorageAccountName $ StorageAccountName;
$上下文=新AzureStorageContext -StorageAccountName $ StorageAccountName -StorageAccountKey $ StorageKey.Primary;###创建集装箱一级的公共访问的Blob存储容器
$容器名称='上传';
新AzureStorageContainer -Context $语境杂牌$容器名称-Permission容器;###上传文件到容器的blob
设置AzureStorageBlobContent -Context $语境 - 集装箱$容器名称 - 文件C:\\ WINDOWS \\ NOTEPAD.EXE;###
###如何取回Azure存储的blob的列表,匿名容器?
###


解决方案

您需要使用的新建 - StorageContext的 - 匿名开关参数为了针对在Azure Blob存储容器匿名身份验证命令。在此之后,只需使用 GET-AzureStorageBlob 命令正常人一样,列出斑点在指定的Blob容器。

  $ AnonContext =新AzureStorageContext -StorageAccountName $ StorageAccountName  - 匿名;
GET-AzureStorageBlob -Context $ AnonContext - 集装箱$容器名称;

I've used the Microsoft Azure PowerShell module to create an Azure storage account and blob container inside the storage account. I've set the blob container to be publicly accessible, but now I need to list the blobs from an anonymous connection.

I'm using the Windows Management Framework Core 5.0 November 2014 Preview with the Azure PowerShell module version 0.8.12.

Here is the code that I used to create the storage account, blob container, and upload a file to the container.

### Authenticate to Microsoft Azure platform
$Username = 'powershell@trevorsullivan.net';
$AzureCredential = Get-Credential -Message 'Enter your Azure password.' -UserName $Username;
Add-AzureAccount -Credential $AzureCredential;

### Select the appropriate Azure subscription
$SubscriptionName = 'Visual Studio Ultimate with MSDN';
Select-AzureSubscription -SubscriptionName $SubscriptionName;

### Create Azure Storage Account
$StorageAccountName = 'opsgility';
New-AzureStorageAccount -StorageAccountName $StorageAccountName;

### Create Azure Storage Context
$StorageKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName;
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageKey.Primary;

### Create a blob storage container with "container" level public access
$ContainerName = 'uploads';
New-AzureStorageContainer -Context $Context -Name $ContainerName -Permission Container;

### Upload a file to the blob container
Set-AzureStorageBlobContent -Context $Context -Container $ContainerName -File c:\windows\notepad.exe;

###
### How do I retrieve a list of Azure storage blobs from the container anonymously?
###

解决方案

You need to use the -Anonymous switch parameter for the New-StorageContext command in order to authenticate anonymously against the Azure blob storage container. After that, simply use the Get-AzureStorageBlob command like normal, to list blobs in the specified blob container.

$AnonContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -Anonymous;
Get-AzureStorageBlob -Context $AnonContext -Container $ContainerName;

这篇关于清单Azure存储的Blob在公共容器匿名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆