Error binding Blob to IAsyncCollector when binding to output blob in Async method

后端 未结 2 722
野趣味
野趣味 2021-01-15 03:20

I\'m trying to bind to a blob output in an Async method following this post: How can I bind output values to my async Azure Function?

I have multipl

2条回答
  •  既然无缘
    2021-01-15 03:55

    Collectors are not supported for Blob output bindings, see this issue.

    For variable amount of output blobs (0 or 1 in your case, but can be any), you would have to use imperative bindings. Remove collection binding from your function.json and then do this:

    public static async Task Run(HttpRequestMessage req, Binder binder)
    {
        if (req.Method == HttpMethod.Post) 
        {
            string jsonContent = await req.Content.ReadAsStringAsync();
    
            var attributes = new Attribute[]
            {    
                new BlobAttribute("testdata/{rand-guid}.txt"),
                new StorageAccountAttribute("test_STORAGE")
            };
    
            using (var writer = await binder.BindAsync(attributes))
            {
                writer.Write(jsonContent);
            }
    
            return req.CreateResponse(HttpStatusCode.OK);
        }
        else 
        {
            return req.CreateResponse(HttpStatusCode.BadRequest);    
        }
    }
    

提交回复
热议问题