简体   繁体   中英

how do you specify more than 1 attribute for dynamic binding to blob?

What am I doing wrong? How do you specify multiple attributes?

I'm attempting to dynamically register a binding to an output blob like so:

        var attributes = new Attribute[]
        {
            new BlobAttribute("success/{CorrelationId}"),
            new StorageAccountAttribute("MyStorageAccount")
        };
        using (var writer = await binder.BindAsync<TextWriter>(attributes))
        {
            writer.Write(JsonConvert.SerializeObject(myQueueItem.Body));
        }

I'm getting the following exception:

在此处输入图片说明

Here's the full code:

public static class OnSchedulingToMMMQueueTriggered
    {
        [FunctionName("OnSchedulingToMMMQueueTriggered")]
        public static async System.Threading.Tasks.Task RunAsync(
            [QueueTrigger("httpqueue", Connection = "OnSchedulingToMMMQueueTriggered:SourceQueueConnection")] Payload myQueueItem,
            [Blob("processed/{CorrelationId}", FileAccess.Write, Connection = "OnSchedulingToMMMQueueTriggered:ProcessedPayloadsConnectionString")]  Stream processedPayload,
            IBinder binder,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem.Body}");

            var attributes = new Attribute[]
            {
                new BlobAttribute("success/{CorrelationId}"),
                new StorageAccountAttribute("MyStorageAccount")
            };
            using (var writer = await binder.BindAsync<TextWriter>(attributes))
            {
                writer.Write(JsonConvert.SerializeObject(myQueueItem.Body));
            }

        }
    }

What am I doing wrong? How do you specify multiple attributes?

The docs do say if you want to use multiple that you should use Binder class instead of IBinder interface.

Use a Binder parameter, not IBinder

For example

public static class OnSchedulingToMMMQueueTriggered {
    [FunctionName("OnSchedulingToMMMQueueTriggered")]
    public static async Task RunAsync(
        [QueueTrigger("httpqueue", Connection = "OnSchedulingToMMMQueueTriggered:SourceQueueConnection")] Payload myQueueItem,
        [Blob("processed/{CorrelationId}", FileAccess.Write, Connection = "OnSchedulingToMMMQueueTriggered:ProcessedPayloadsConnectionString")]  Stream processedPayload,
        Binder binder, //<--NOTE *Binder* not *IBinder*
        ILogger log) {

        log.LogInformation($"C# Queue trigger function processed: {myQueueItem.Body}");

        var attributes = new Attribute[] {
            new BlobAttribute("success/{CorrelationId}"),
            new StorageAccountAttribute("MyStorageAccount")
        };
        using (var writer = await binder.BindAsync<TextWriter>(attributes)) {
            writer.Write(JsonConvert.SerializeObject(myQueueItem.Body));
        }
    }
}

Reference Multiple attribute example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM