I have a working .NET6 in-proc Azure Function. I'm in the process of converting it to an isolated worker process (out-of-proc) .net7 function.
I have a HttpTrigger function that should get a file from the blob-storage. Since the blob-storage is case-sensitive and all files are saved in upper-case, I need to make the input upper-case as well.
With the in-proc function, I did that by injecting Microsoft.Azure.WebJobs.IBinder binder
and then use binder.BindAsync<byte[]>(new Microsoft.Azure.WebJobs.BlobAttribute($"%BlobContainerName%/{fooUpper}", FileAccess.Read)
This is the .net6 in-proc function:
[Function(nameof(GetFile))]
public async Task<IActionResult> GetFile(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "bar/{foo}")] HttpRequest req,
Microsoft.Azure.WebJobs.IBinder binder, Microsoft.Azure.WebJobs.ExecutionContext context, string foo)
{
// The file name is always upper-case:
var fooUpper = foo.ToUpperInvariant();
var blobStream = await binder.BindAsync<byte[]>(
new Microsoft.Azure.WebJobs.BlobAttribute($"%BlobContainerName%/{fooUpper}", FileAccess.Read),
req.FunctionContext.CancellationToken).ConfigureAwait(false);
return await ExecuteAsync(fooUpper, context.FunctionDirectory, blobStream,
req.FunctionContext.CancellationToken)
.ConfigureAwait(false);
}
Of course, I tried migrating this function to a .net7 isolated function by replacing HttpRequest req
with HttpRequestData req
and it compiles but when I run it binder
is always null
.
What is the isolated function version of my function?
- Do I need to create a custom attribute?
- Or create some middleware that makes the URL upper-case?
- Or should I create a service that I register during start-up and use with DI in the function class?
Please advice.
Check if my below findings helpful to fix your issue:
AFAIK,
BlobContainerClient
should work with the .NET Isolated Process Version 7 in Azure Functions usingAzure.Storage.Blobs
NuGet Package as shown in this SO Answer #75015570 by the user @HariKrishna and MS DOC.If you use the NuGet Package
Azure.Storage.Blobs
, you can initialize theBlobContainerClient
class-objects which is compatible in .NET Isolated Process and for working with the Blob Container Objects, you have to initialize the BlobServiceClient for Connecting to Storage Account and getting access to the Blob Container.Here is the GitHub Article on Azure Functions .NET Isolated Process of using the Ibinder input parameter for data binding and there are some examples provided in the same article for working in the context of Ibinder and StorageAccountAttribute such as
Microsoft.Azure.WebJobs.BlobAttribute
.