Precompiled Azure function and CloudTable binding output doesn't work

后端 未结 3 740
既然无缘
既然无缘 2020-12-17 03:52

I\'m using a precompiled Azure Function that looks:

public static async Task Run(Stream inputBlob, Stream outputJson, Stream outputXml, CloudTable schedulerT         


        
3条回答
  •  情歌与酒
    2020-12-17 04:35

    According to your description, I have tested this issue about binding to the table output, I could make it work as expected. Here is my code snippet, you could refer to it.

    function.json

    {
      "bindings": [
        {
          "name": "inputBlob",
          "type": "blobTrigger",
          "direction": "in",
          "path": "input/{name}",
          "connection": "AzureStorageConnectionString"
        },
        {
          "type": "table",
          "name": "outTable",
          "tableName": "UploadFile",
          "connection": "AzureStorageConnectionString",
          "direction": "out"
        }
      ],
      "disabled": false
    }
    
    • ICollector
    #r "Microsoft.WindowsAzure.Storage"
    
    using Microsoft.WindowsAzure.Storage.Table;
    using Microsoft.WindowsAzure.Storage.Blob;
    
    public static void Run(CloudBlockBlob inputBlob, ICollector outTable, TraceWriter log)
    {   
        string blobUri=inputBlob.StorageUri.PrimaryUri.ToString();
        log.Info($"C# Blob  trigger function triggered, blob path: {blobUri}");
    
        outTable.Add(new UploadFile()
        {
            PartitionKey = "Functions",
            RowKey = Guid.NewGuid().ToString(),
            Name = blobUri
        });
    }
    
    public class UploadFile : TableEntity
    {
        public string Name { get; set; }
    }
    
    • CloudTable
    #r "Microsoft.WindowsAzure.Storage"
    
    using Microsoft.WindowsAzure.Storage.Table;
    using Microsoft.WindowsAzure.Storage.Blob;
    
    public static void Run(CloudBlockBlob inputBlob,CloudTable outTable, TraceWriter log)
    {   
        string blobUri=inputBlob.StorageUri.PrimaryUri.ToString();
        log.Info($"C# Blob  trigger function triggered, blob path: {blobUri}");
    
        outTable.Execute(TableOperation.Insert(new UploadFile()
        {
            PartitionKey = "Functions",
            RowKey = Guid.NewGuid().ToString(),
            Name = blobUri
        }));
    }
    
    public class UploadFile : TableEntity
    {
        public string Name { get; set; }
    }
    

    Modify your code and click Save, if the compilation executes successfully, then when the function is triggered, you could see the following log and the record is added to Azure Table Storage.

    For more details, you could refer to this official document about storage table binding for Azure function.

提交回复
热议问题