【问题标题】:Retrieve photos on Azure在 Azure 上检索照片
【发布时间】:2020-06-02 07:00:29
【问题描述】:

我在 Azure 上有一个任务要做。

在 Azure 上,我需要使用这样的链接获取照片:

https://picture.blob.core.windows.net/datapicture

我收到了这份文件。

https://docs.microsoft.com/en-us/powershell/module/azure.storage/get-azurestorageblobcontent?view=azurermps-6.13.0

目标是制作一个 powershell 脚本,允许您使用 Azure 检索此路径中的照片。

我没有登录密钥,只有登录用户名和密码。

我认为我的连接模型是:

Login-AzureRmAccount

$SourceResourceGroupName = "...";
$SourceServerName = "...";
$Database = "...";
$ServerInstance =  "...";
$Username = "...";
$Password = "..."

$con.ConnectionString = "Server=$ServerInstance;
                        uid=$Username; 
                        pwd=$Password;
                        Database=$Database;
                        Integrated Security=False;"         
$con.Open();

提前感谢您对我的帮助。

【问题讨论】:

  • 这是什么意思? “我没有登录密钥,只有登录用户名和密码。” Blob 存储通过对称密钥、AzureAD 进行身份验证或根本不进行身份验证(如果是公共 Blob)。没有用户名/密码基本身份验证
  • 可能没有用户/密码基本身份验证。我只想使用 Azure 下载此链接的图像文件,路径如下:picture.blob.core.windows.net/datapicture
  • 找到可能满足您要求的可选解决方案。可以请您检查一下吗?

标签: database azure powershell server


【解决方案1】:

您似乎正在尝试从Azure Blob Storage 下载文件。它不像数据库那样工作。

正如评论中所言,Azure 存储支持对称密钥和 Azure AD 身份验证。或者,您可以将文件设置为公开,从而可以直接访问它。

您使用了Login-AzureRmAccount 命令。因此,您应该能够下载如下 Blob:

$ResourceGroup = "Jack"
$StorageAccount = "storagetest789"
$Container = "function"
Set-AzureRmCurrentStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccount
Get-AzureStorageBlobContent -Container $Container -Blob "User1.txt" -Destination 'D:\'

更新

普通的存储 blob URL 应如下所示:https://{storage_account_name}.blob.core.windows.net/{container_name}/{blob_name}

因此,您可能会得到$StorageAccount$Container$Blob,如下所示:

$UserName = '.......';
$Password = '.........';
$Secret = ConvertTo-SecureString -String $Password -AsPlainText -Force;
$PsCred = New-Object System.Management.Automation.PSCredential($UserName, $Secret);
Login-AzureRmAccount -Credential $PsCred;

$ResourceGroup = '';
$URL = 'https://{storage_account_name}.blob.core.windows.net/{container_name}/{blob_name}';

$StorageAccount = $URL.Substring('https://'.Length,$URL.IndexOf(".")-'https://'.Length);
$Path = $URL.Substring($URL.IndexOf('.blob.core.windows.net/')+'.blob.core.windows.net/'.Length);
$Container = $Path.Substring(0,$Path.IndexOf('/'));
$Blob = $Path.Substring($Container.Length+1);

Set-AzCurrentStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccount;
Get-AzStorageBlobContent -Container $Container -Blob $Blob -Destination 'D:\';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多