【问题标题】:How to get the Azure Blob Uri from Azure Functions with Powershell?如何使用 Powershell 从 Azure Functions 获取 Azure Blob Uri?
【发布时间】:2023-03-31 11:16:01
【问题描述】:

我在 Powershell 上有一个 BlobTrigger 天蓝色函数。我正在尝试获取 blob uri,以便使用以下 scipt 从此 vhd blob 创建托管磁盘:

$diskConfig = New-AzDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI

New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName

从 cloud shell,我可以通过以下代码获取 uri:

$(Get-AzureStorageBlob -Blob myblob -Container 'mycontainer' -Context $StorageContext).ICloudBlob.uri.AbsoluteUri

但是对于 Azure Functions,我不能。我的 AF 代码如下:

# Input bindings are passed in via param block.
param([byte[]] $InputBlob, $TriggerMetadata)

# Write out the blob name and size to the information log.
Write-Host "PowerShell Blob trigger function Processed blob! Uri: $($InputBlob.ICloudBlob.uri.AbsoluteUri)"

$InputBlob.ICloudBlob.uri.AbsoluteUri 返回空。我检查了blob documentation,但找不到任何解决方案。

你有什么建议吗?

【问题讨论】:

  • $InputBlob 已经包含来自 blob 的数据作为字节数组。您确定需要 URI 吗?
  • 我已将创建 NewAzDisk 的脚本添加到问题中。在那里,我需要 -SourceUri 参数的 blob uri。我不知道如何通过使用带有 Powershell 的字节数组来创建 NewAzDisk
  • $TriggerMetadata.Uri 应该给你 URI

标签: azure powershell azure-functions azure-blob-storage


【解决方案1】:

您可以尝试$TriggerMetadata.Name 来获取名称,或者按照@Anatoli Beliaev 的建议尝试$TriggerMetadata.Uri

作为替代方案,您可以尝试这样的事情(未经测试):

param([Microsoft.Azure.Storage.Blob.ICloudBlob] $myBlob)

这至少在 .NET 中有效,并且文档看起来可能表现类似。

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#type-casting-for-triggers-and-bindings

对于某些绑定,如 blob 绑定,您可以指定参数的类型。

例如,要将 Blob 存储中的数据作为字符串提供,请将以下类型转换添加到我的参数块:

param([string] $myBlob)

【讨论】:

  • [string] $myBlob 仍会为您提供与 blob 相同的内容,只是转换为字符串。
  • 啊,显然是这样,我不知何故弄糊涂了。谢谢你的信息,我改变了答案。
  • @AlexAIT 我正在使用 $TriggerMetaData.Name 来获取 blob 的名称,但它恰好是空的。如果可能,请让我知道快速修复。否则我会发布不同的线程。
猜你喜欢
  • 2022-11-06
  • 1970-01-01
  • 2019-04-25
  • 1970-01-01
  • 1970-01-01
  • 2020-06-25
  • 2019-06-12
  • 2018-06-05
  • 1970-01-01
相关资源
最近更新 更多