简体   繁体   English

如何从 Azure 函数中获取多个 blob?

[英]How can I get multiple blobs out of an Azure Function?

I'm coding a C# function which is triggered by the upload of a blob.我正在编写一个由 blob 上传触发的 C# 函数。 I would like to read another file in the container.我想读取容器中的另一个文件。 How would the input binding bring the second blob?输入绑定将如何带来第二个 blob?

public static async Task Run([BlobTrigger("csv/{name}.csv", Connection = "StorageConnectionAppSetting")]Stream myBlob, string name, ILogger log)

In addition to this question, how can I reference values from the local.settings.json in my code?除了这个问题,如何在我的代码中引用 local.settings.json 中的值? I'm able to reference the "StorageConnectionAppSetting" on the input binding but I'm not sure how to do the same for portions of my code where I'm creating clients using APIKEYs.我可以在输入绑定上引用“StorageConnectionAppSetting”,但我不确定如何对我使用 APIKEY 创建客户端的代码部分执行相同的操作。

Thanks!谢谢!

  1. A blob-trigger can be a single blob, but you can add an input binding to your function. blob 触发器可以是单个 blob,但您可以向函数添加输入绑定。 In this case you can add an input binding to CloudBlobContainer by adding a reference to the storage SDK, and then read any blobs in that container.在这种情况下,您可以通过添加对存储 SDK 的引用来向CloudBlobContainer添加输入绑定,然后读取该容器中的任何 Blob。 https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=csharp#usage . https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=csharp#usage

Another option would be not to use input binding and read the container and its contents the way you would normally do using storage SDK.另一种选择是不使用输入绑定并像通常使用存储 SDK 那样读取容器及其内容。 You will need to add reference to Microsoft.Azure.Storage.Blob in both the cases.在这两种情况下,您都需要添加对Microsoft.Azure.Storage.Blob引用。

  1. For app settings you can use System.Environment.GetEnvironmentVariable("APIKEY");对于应用程序设置,您可以使用System.Environment.GetEnvironmentVariable("APIKEY"); , assuming APIKEY is your customer setting. ,假设APIKEY是您的客户设置。 Remember, local.settings.json will only be local and you will need to set these values in Azure either via Azure Portal or your CI/CD pipeline via and ARM template.请记住,local.settings.json 只会是本地的,您需要通过 Azure 门户或通过 ARM 模板的 CI/CD 管道在 Azure 中设置这些值。

You can also use Azure functions dependency injection and inject configuration.您还可以使用 Azure 函数依赖项注入和注入配置。 Check the section Working with options and settings at https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#working-with-options-and-settings检查https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#working-with-options-and-settings 上的“ Working with options and settings ”部分

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM