azure - 无法以编程方式下载 Blob
问题描述
我们在 azure 存储容器中有多个 blob,当我们使用 powershell 下载 blob(文件)时,9 个文件中有 8 个下载,但是第 9 个失败。这个文件绝对没有什么不同,我在 blob 属性中注意到的唯一一件事是“内容 MD5”是空白的,但是其他 8 个有一个值。不知道这是什么或者它是否与它有任何关系,我希望有人能解释为什么这是一个文件没有下载..
提前致谢 :)
解决方案
尝试使用以下代码从 Azure Blob 下载文件
function Get-DLLFile
{
param(
[Parameter(Mandatory=$true)] [string] $connectionString,
[Parameter(Mandatory=$true)] [String[]] $blobsName,
[Parameter(Mandatory=$true)] [string] $container,
[Parameter(Mandatory=$true)] [string] $filePath
)
Try
{
foreach ($blobName in $blobsName)
{
$file = $filePath + $blobName
$fileAvailable = Get-Item -Path $file -ErrorAction SilentlyContinue
if($null -eq $fileAvailable)
{
$ctx = New-AzureStorageContext -ConnectionString $connectionString
New-Item -Path $filePath -ItemType Directory -Force | Out-Null
Get-AzureStorageBlobContent -Blob $blobName -Container $container -Destination $filePath -Context $ctx -Force | out-null
}
}
}
Catch
{
$_.Exception.Message
}
}
Get-DLLFile -blobsName "File1.csv","File2.json" -container "myContainer" -connectionString "$(BlobConnectionString)" -filePath "$(System.DefaultWorkingDirectory)/Download"
希望这应该有效,如果没有请分享您遇到的异常。
推荐阅读
- java - 用于覆盖的 JSON 模式 - 最佳实践
- react-native - 有没有人设法用 react-native 0.58 制作 react-native-device-info ?
- php - 使用 PHP 将上传的文件存储到 NAS
- javascript - 尝试将新任务添加到现有项目时,Laravel + React 返回错误
- docusignapi - 添加补充文件。使用 viewTabs 创建指向其他文档的链接
- unity3d - Runnable.Run / StartCoroutine 从 Unity 调用 Watson 服务
- java - 如何使用页面工厂在 testng 中运行多个测试类?
- python - 如果第一个失败,SMTPLIB 是否支持重试邮件服务器中的其他 IP?
- cassandra - RHEL 和 CentOS 上的 Scylla 安装问题
- c# - 如何使用 It.IsAny 作为参数?