Azure Blob 触发器 - 基于输入容器的动态 BlobOutput 绑定(bind)名称

标签 azure azure-functions azure-blob-storage azure-blob-trigger

        [Function("Function1")]
        [BlobOutput("test-samples-output/{name}", Connection = "ConnectionString1")]

        public string Run([BlobTrigger("test-samples-trigger/{name}", Connection = "ConnectionString1")] string myBlob,
            string name, string blobTrigger)
        {
            _logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name} \n Data: {myBlob}");
            
            return myBlob;
        }

我有一个 blob 触发器设置为“test-samples-trigger/{name}”。我想将 BlobOutput 设置为使用输入容器名称“{input-container-name}-output/{name}”。有没有办法将 BlobOuput 字符串设置为动态指向该位置?

最佳答案

从我这边复制后,实现您的要求的一种方法是使用 GetEnvironmentVariable 读取变量,其中值是从 local.settings.json 读取的。下面是对我有用的完整代码。

Function1.cs

using System;
using System.IO;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp13
{
    public class Function1
    {
        [FunctionName("Function1")]
        public void Run([BlobTrigger("samples-workitems/{name}", Connection = "connstr")]Stream myBlob,
            [Blob("%outputContainer%/{name}", FileAccess.Write, Connection = "connstr")] Stream outputBlob, 
            string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");

            string outputContainer = Environment.GetEnvironmentVariable("outputContainer");

            outputBlob.Write();
        }
    }
}

本地.settings.json

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "<ConnectionString>",
    "connstr": "<ConnectionString>",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "outputContainer": "sample"
  }
}

结果:

enter image description here

enter image description here

关于Azure Blob 触发器 - 基于输入容器的动态 BlobOutput 绑定(bind)名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75447116/

相关文章:

java - 如何通过 azure 设备配置服务将自定义错误消息从 azure 函数发送到 iot 设备?

azure-active-directory - 使用托管标识从本地 Azure 函数查询 Azure SQL 数据库

java - Azure Java SDK : How to disable logging to console?

azure - 获取 botframework 中建议操作的值

java - BadRequest 使用 Azure 服务管理 API 创建 VM

azure - 限制Azure函数自动缩放

azure - 如何将azure上的数据从一个资源组复制到另一个资源组?

java - Azure函数无法找到具有给定输入的方法签名

azure - 使用 Arm 模板设置存储帐户 key

powershell - 使用 Powershell 获取 Azure Function 路由参数(段)