简体   繁体   English

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

[英]How to write data in Azure Blob storage programmatically?

I am using below PowerShell script to read JSON data using REST API call from source.我正在使用下面的 PowerShell 脚本来读取 JSON 数据,使用来自源调用的 REST ZDB974238714CA8DE1434A7CE1D083 Now I want to load the data of $Result to the Azure Blob Storage.现在我想将 $Result 的数据加载到 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. Save the JSON into one file then upload the file to Azure blob将 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. Directly upload to Azure blob直接上传到 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)

在此处输入图像描述 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将二进制数据作为图像写入 azure blob 存储 c# - How to write binary data as image into azure blob storage c# 写入 Azure 存储 Blob (PowerShell) - Write to Azure Storage Blob (PowerShell) 如何使用Azure Blob存储装载数据? - How to mount data with Azure Blob Storage? 如何使用 blob 服务以编程方式删除 azure 存储中未提交的块? - how to programmatically delete uncommitted blocks in azure storage using blob service? 将Json数据从DataFrame写入Azure Blob存储 - Write Data as Json from DataFrame to Azure Blob Storage 如何编写传输到数据湖的Azure Blob存储触发器 - How do i write an Azure Blob storage trigger that transfers to a data lake 如何在 Python 中使用 Azure Functions 的 Azure Blob 存储绑定将 JSON 数据上传到 Azure 存储 blob - How to upload JSON data to Azure storage blob using Azure Blob storage bindings for Azure Functions in Python Azure Blob存储REST Api-如何将标头编写为字符串 - Azure Blob storage REST Api - How to write headers as string 如何监控 Azure Blob 存储上的读写活动 - How to monitor read write activities on Azure Blob Storage 如何将 a.hyper 文件(在 DataBricks 中)写入 Blob 存储(在 Azure 中)? - How to Write a .hyper file (in DataBricks) to Blob Storage (in Azure)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM