I have configured the Azure functions to output file to Blob container with current date using datetime function in binding but it is creating a UTC date folder.
I even changed the WEBSITE_TIME_ZONE to local time referring the list here but still creating UTC date folder in the blob when I want local time.
My binding code is:
{
"connection": "AzureWebJobsStorage",
"name": "Blobstr3",
"path": "outcontainer/{datetime:ddMMyyyy}/{rand-guid}.txt",
"direction": "out",
"type": "blob"
}
It would be great if someone could please help me out here?
CodePudding user response:
There is no binding expression for local time.
The official Azure Functions binding expression patterns states:
The binding expression DateTime resolves to DateTime.UtcNow.
To use local time you would have save to blob yourself or use binding at runtime (again from Azure Functions binding expression patterns):
Binding at runtime
In C# and other .NET languages, you can use an imperative binding pattern, as opposed to the declarative bindings in function.json and attributes. Imperative binding is useful when binding parameters need to be computed at runtime rather than design time. To learn more, see the C# developer reference or the C# script developer reference.
Here's an example from how to do it from Develop C# class library functions using Azure Functions
Single attribute example
The following example code creates a Storage blob output binding with blob path that's defined at run time, then writes a string to the blob.
public static class IBinderExample { [FunctionName("CreateBlobUsingBinder")] public static void Run( [QueueTrigger("myqueue-items-source-4")] string myQueueItem, IBinder binder, ILogger log) { log.LogInformation($"CreateBlobUsingBinder function processed: {myQueueItem}"); using (var writer = binder.Bind<TextWriter>(new BlobAttribute( $"samples-output/{myQueueItem}", FileAccess.Write))) { writer.Write("Hello World!"); }; } }