如何在Azure函数中使用return属性?

时间:2019-03-29 16:10:17

标签: c# .net azure-functions

是否可以通过在属性中指定连接信息将响应直接返回到存储帐户中?

在下面的示例中,我认为这与我要查找的内容类似:

[return: EventHub("results", Connection = "EhConnectionString")]

完整上下文:

    [FunctionName("DequeAndForwardOn")]
    [return: EventHub("results", Connection = "EhConnectionString")]
    public static string Run([ServiceBusTrigger("testqueue", Connection = "SbConnectionString")]string myQueueItem, TraceWriter log)
    {
        log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
        EventHubOutput message = JsonConvert.DeserializeObject<EventHubOutput>(myQueueItem);
        message.ProcessedAtUtc = DateTime.UtcNow;
        string json = JsonConvert.SerializeObject(message);
        return json;
    }

我的期望是这样的:

    [return: StorageAccount("myStorageAccount/{myBlobContainer}", Connection = "StorageConnectionString")]

1 个答案:

答案 0 :(得分:1)

Blob绑定的Functions documentation说明了如何执行此操作。它与EventHub绑定略有不同。

[FunctionName("ResizeImage")]
    public static void Run(
    [BlobTrigger("sample-images/{name}")] Stream image,
    [Blob("sample-images-sm/{name}", FileAccess.Write)] Stream imageSmall, //output blob
    [Blob("sample-images-md/{name}", FileAccess.Write)] Stream imageMedium)
    {
         //your code here
    }