Dynamic output file name of ApiHubFile Azure Function binding (one drive, drop box etc)

前端 未结 2 1031
小鲜肉
小鲜肉 2021-01-22 21:14

I have an Azure Function with Timer Trigger, and then I want to generate a file with dynamic (defined in runtime) name and contents and save it to e.g. OneDrive.

My func

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 21:38

    To have full control over the name and path of an output during function execution, you need to use imperative binding

    For example: function.json

    {
          "type": "blob",
          "name": "outputBinder",
          "path": "export/test",
          "connection": "AzureWebJobsStorage",
          "direction": "out"
    },
    

    Function:

    public static async Task Run(HttpRequestMessage req, TraceWriter log, IBinder outputBinder)
    {
         var attribute new BlobAttribute($"{some dynamic path}/{some dynamic filename}", FileAccess.Write);
         using (var stream = await outputBinder.BindAsync(attribute))
         {
              // do whatever you want with this stream here...
         }
    }
    

提交回复
热议问题