Azure Blob触发器-基于输入容器的动态Blob输出绑定名称

tcomlyy6  于 2023-02-19  发布在  其他
关注(0)|答案(1)|浏览(97)
[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}”。是否有办法将BlobOutput字符串设置为动态指向此位置?

zi8p0yeb

zi8p0yeb1#

从我的结束复制后,实现您的要求的一种方法是使用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();
        }
    }
}

local.settings.json

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

结果:

相关问题