0
        [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;
        }

I have a blob trigger set to 'test-samples-trigger/{name}'. I want to set the BlobOutput to use the input container name '{input-container-name}-output/{name}'. Is there a way to set the BlobOuput string to dynamically point to this location?

CDWatson
  • 41
  • 4

1 Answers1

1

After reproducing from my end, One way to achieve your requirement is to read variable using GetEnvironmentVariable where the value is read from local.settings.json. Below is the complete code that worked for me.

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"
  }
}

Results:

enter image description here

enter image description here

SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
  • Thanks, this would work for a single output location, but I was hoping to dynamically create it based on the input. For example, two triggers "samples-workitems1" and "samples-workitems2" could dynamically point to the outputs "samples-workitems1-output" and "samples-workitems2-output" respectively. – CDWatson Feb 16 '23 at 10:05
  • 1
    @CDWatson AFAIK, to achieve your requirement you can create multiple functions in your function app. – SwethaKandikonda Feb 16 '23 at 10:13
  • That is what I currently have. Each function has a custom output object with the correct output bindings for that function. Across 10+ functions this looks quite clumsy having this for each one so was wondering if a solution was possible to only have one of these objects with a relative path. – CDWatson Feb 16 '23 at 10:32
  • @CDWatson If Azure functions is not a must thing, then you can use logic apps in this case. – SwethaKandikonda Feb 16 '23 at 10:40