英文:
Azure Blob Trigger - Dynamic BlobOutput Binding Name Based on Input Container
问题
[Function("Function1")]
[BlobOutput("{input-container-name}-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;
}
英文:
[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?
答案1
得分: 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:
"
英文:
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:
答案2
得分: 0
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "YOUR_AZURE_STORAGE_CONNECTION_STRING",
"ContainerName": "mycontainer" // 默认容器名称
}
}
英文:
local.setting.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "YOUR_AZURE_STORAGE_CONNECTION_STRING",
"ContainerName": "mycontainer" // Default container name
}
}
using System.Configuration;
public static void ProcessBlob(
[BlobTrigger("%ContainerName%/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob,
string name)
{
// Your code here
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论