如何以编程方式在Azure Blob存储中写入数据? [英] How to write data in Azure Blob storage programmatically?

查看:59
本文介绍了如何以编程方式在Azure Blob存储中写入数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using below PowerShell script to read JSON data using REST API call from source. Now I want to load the data of $Result to the Azure Blob Storage. Any idea please?

$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

推荐答案

关于此问题,您可以使用以下方式

Regarding the issue, you can use the following ways

  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)

这篇关于如何以编程方式在Azure Blob存储中写入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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