动态输出Blob存储容器名称

问题描述 投票:0回答:1

为Azure函数配置输出Blob存储容器时,是否可以通过某种方式运行一些代码来生成将存储BLOB的路径?更准确地说,每次此函数被触发时,我想在路径中使用一个新的GUID。这样的事情(代码不起作用):

[FunctionName("BlobTriggered")]        
public static void BlobTriggered(
    [BlobTrigger("myContainer/{name}.{extension}")] Stream myBlob,
    [Blob("myContainer/{Guid.NewGuid()}", FileAccess.Write)] Stream outputContainer,

    string name,
    string extension,
    TraceWriter log)
{
    ...
}

在上面的代码中,我正在尝试使用GUID生成Guid.NewGuid(),但这是行不通的。有没有类似的方法可以做到这一点?

c# azure azure-functions blob azure-storage-blobs
1个回答
0
投票

此代码将起作用:(我正在使用Storage Blob SDK。]

using System;
using System.IO;
using Azure.Storage.Blobs;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp53
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("samples-workitems/{name}.{extension}", Connection = "str")]Stream myBlob, 
            string name, ILogger log)
        {
            log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
            string connectionString = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;xxx;EndpointSuffix=core.windows.net";
            BlobServiceClient myClient = new BlobServiceClient(connectionString);
            var container = myClient.GetBlobContainerClient("samples-workitems");
            string a = Guid.NewGuid().ToString();
            var blockBlob = container.GetBlobClient(a);
            blockBlob.Upload(myBlob);
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.