如何以编程方式将数据写入Azure Blob存储?

2024-05-01

我正在使用下面的 PowerShell 脚本通过 REST API 调用从源读取 JSON 数据。现在我想将 $Result 的数据加载到 Azure Blob 存储中。有什么想法吗?

$Params = @{
 "URI" = 'https://3ea5e53b-817e-4c41-ae0b-c5afc1610f4e-bluemix.cloudant.com/test/_all_docs?include_docs=true'
}
 
$Result = Invoke-RestMethod @Params | ConvertTo-Json -Depth 9

针对该问题,您可以使用以下方式

  1. 将 JSON 保存到一个文件中,然后将该文件上传到 Azure blob
$Params = @{
 "URI" = 'https://3ea5e53b-817e-4c41-ae0b-c5afc1610f4e-bluemix.cloudant.com/test/_all_docs?include_docs=true'
}
 
$Result = Invoke-RestMethod @Params | ConvertTo-Json -Depth 9
$Result | Out-File "D:\file.json"

$context=New-AzStorageContext -StorageAccountName "andyprivate" -StorageAccountKey ""

Set-AzStorageBlobContent -File "D:\file.json" `
  -Container "" `
  -Blob "file.json" `
  -Context $context `
  -StandardBlobTier Hot

  1. 直接上传到Azure blob
$Params = @{
 "URI" = 'https://3ea5e53b-817e-4c41-ae0b-c5afc1610f4e-bluemix.cloudant.com/test/_all_docs?include_docs=true'
}
 
$Result = Invoke-RestMethod @Params | ConvertTo-Json -Depth 9
Write-Host "the result is :"
$Result 

$context=New-AzStorageContext -StorageAccountName "andyprivate" -StorageAccountKey ""

$container=Get-AzStorageContainer -Name "input" -Context $context

$content = [system.Text.Encoding]::UTF8.GetBytes($Result)

$container.CloudBlobContainer.GetBlockBlobReference("my.json").UploadFromByteArray($content,0,$content.Length)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何以编程方式将数据写入Azure Blob存储? 的相关文章

随机推荐