title | description | ms.topic | ms.custom | ms.date | zone_pivot_groups |
---|---|---|---|---|---|
Azure Blob storage trigger and bindings for Azure Functions |
Learn to use the Azure Blob storage trigger and bindings in Azure Functions. |
reference |
devx-track-extended-java, devx-track-js, devx-track-python, devx-track-ts |
11/11/2022 |
programming-languages-set-functions |
Azure Functions integrates with Azure Storage via triggers and bindings. Integrating with Blob storage allows you to build functions that react to changes in blob data as well as read and write values.
Action | Type |
---|---|
Run a function as blob storage data changes | Trigger |
Read blob storage data in a function | Input binding |
Allow a function to write blob storage data | Output binding |
::: zone pivot="programming-language-csharp"
The extension NuGet package you install depends on the C# mode you're using in your function app:
Functions execute in an isolated C# worker process. To learn more, see Guide for running C# Azure Functions in an isolated worker process.
[!INCLUDE functions-in-process-model-retirement-note]
Functions execute in the same process as the Functions host. To learn more, see Develop C# class library functions using Azure Functions.
In a variation of this model, Functions can be run using C# scripting, which is supported primarily for C# portal editing. To update existing binding extensions for C# script apps running in the portal without having to republish your function app, see Update your extensions.
The functionality of the extension varies depending on the extension version:
This section describes using a class library. For C# scripting, you would need to instead install the extension bundle, version 4.x.
[!INCLUDE functions-bindings-supports-identity-connections-note]
This version allows you to bind to types from Azure.Storage.Blobs. Learn more about how these new types are different from WindowsAzure.Storage
and Microsoft.Azure.Storage
and how to migrate to them from the Azure.Storage.Blobs Migration Guide.
This extension is available by installing the Microsoft.Azure.WebJobs.Extensions.Storage.Blobs NuGet package, version 5.x.
Using the .NET CLI:
dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage.Blobs --version 5.0.0
[!INCLUDE functions-bindings-storage-extension-v5-tables-note]
This section describes using a class library. For C# scripting, you would need to instead install the extension bundle, version 2.x.
Working with the trigger and bindings requires that you reference the appropriate NuGet package. Install the Microsoft.Azure.WebJobs.Extensions.Storage NuGet package, version 4.x. The package is used for .NET class libraries while the extension bundle is used for all other application types.
[!INCLUDE functions-runtime-1x-retirement-note]
Functions 1.x apps automatically have a reference the Microsoft.Azure.WebJobs NuGet package, version 2.x.
[!INCLUDE functions-storage-sdk-version]
[!INCLUDE functions-bindings-supports-identity-connections-note]
This version allows you to bind to types from Azure.Storage.Blobs. Learn more about how these new types are different from WindowsAzure.Storage
and Microsoft.Azure.Storage
and how to migrate to them from the Azure.Storage.Blobs Migration Guide.
This version supports configuration of triggers and bindings through .NET Aspire integration.
Add the extension to your project by installing the Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs NuGet package, version 5.x or later.
Using the .NET CLI:
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs
[!INCLUDE functions-bindings-storage-extension-v5-isolated-worker-tables-note]
If you're writing your application using F#, you must also configure this extension as part of the app's startup configuration. In the call to ConfigureFunctionsWorkerDefaults()
or ConfigureFunctionsWebApplication()
, add a delegate that takes an IFunctionsWorkerApplication
parameter. Then within the body of that delegate, call ConfigureBlobStorageExtension()
on the object:
let hostBuilder = new HostBuilder()
hostBuilder.ConfigureFunctionsWorkerDefaults(fun (context: HostBuilderContext) (appBuilder: IFunctionsWorkerApplicationBuilder) ->
appBuilder.ConfigureBlobStorageExtension() |> ignore
) |> ignore
Add the extension to your project by installing the Microsoft.Azure.Functions.Worker.Extensions.Storage NuGet package, version 4.x.
Functions version 1.x doesn't support isolated worker process.
::: zone-end
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-java,programming-language-powershell"
The Blob storage binding is part of an extension bundle, which is specified in your host.json project file. You may need to modify this bundle to change the version of the binding, or if bundles aren't already installed. To learn more, see extension bundle.
[!INCLUDE functions-bindings-supports-identity-connections-note]
You can add this version of the extension from the extension bundle v3 by adding or replacing the following code in your host.json
file:
[!INCLUDE functions-extension-bundles-json-v3]
To learn more, see Update your extensions.
You can install this version of the extension in your function app by registering the extension bundle, version 2.x.
Functions 1.x apps automatically have a reference to the extension.
::: zone-end
::: zone pivot="programming-language-csharp"
The binding types supported for .NET depend on both the extension version and C# execution mode, which can be one of the following:
An isolated worker process class library compiled C# function runs in a process isolated from the runtime.
An in-process class library is a compiled C# function runs in the same process as the Functions runtime.
Choose a version to see binding type details for the mode and version.
The Azure Blobs extension supports parameter types according to the table below.
| Binding scenario | Parameter types |
|-|-|-|
| Blob trigger | StreamTextReader
string
byte[]
BinaryData
BlobClient1
BlockBlobClient1
PageBlobClient1
AppendBlobClient1
BlobBaseClient1|
| Blob input (single blob)| StreamTextReader
string
byte[]
BinaryData
BlobClient1
BlockBlobClient1
PageBlobClient1
AppendBlobClient1
BlobBaseClient1|
| Blob input (multiple blobs from a container)| IEnumerable<T>
where T
is one of the single blob input binding types |
| Blob output (single blob) | StreamTextWriter
string
byte[]
|
| Blob output (multiple blobs) | ICollector<T>
or IAsyncCollector<T>
where T
is one of the single blob output binding types |
1 The client types require the Access
property of the attribute to be set to FileAccess.ReadWrite
.
For examples using these types, see the GitHub repository for the extension. Learn more about types from the Azure SDK, how they are different from earlier versions, and how to migrate to them from the Azure.Storage.Blobs Migration Guide.
Earlier versions of the extension exposed types from the now deprecated Microsoft.Azure.Storage.Blob namespace. Newer types from Azure.Storage.Blobs are exclusive to extension 5.x and higher.
This version of the Azure Blobs extension supports parameter types according to the table below.
| Binding | Parameter types |
|-|-|-|
| Blob trigger | StreamTextReader
string
byte[]
ICloudBlob1
CloudBlockBlob1
CloudPageBlob1
CloudAppendBlob1|
| Blob input | StreamTextReader
string
byte[]
ICloudBlob1
CloudBlockBlob1
CloudPageBlob1
CloudAppendBlob1|
| Blob output | StreamTextWriter
string
byte[]
|
1 These types require the Access
property of the attribute to be set to FileAccess.ReadWrite
.
2 IEnumerable<T>
provides an enumeration of blobs in the container. Here, T
can be any of the other supported types.
Functions 1.x exposed types from the deprecated Microsoft.WindowsAzure.Storage namespace. Newer types from Azure.Storage.Blobs are exclusive to Extension 5.x and higher. To use these, you will need to upgrade your application to Functions 4.x.
The isolated worker process supports parameter types according to the tables below.
Blob trigger
[!INCLUDE functions-bindings-storage-blob-trigger-dotnet-isolated-types]
Blob input binding
[!INCLUDE functions-bindings-storage-blob-input-dotnet-isolated-types]
Blob output binding
[!INCLUDE functions-bindings-storage-blob-output-dotnet-isolated-types]
Earlier versions of extensions in the isolated worker process only support binding to string parameters. Additional options are available to extension 5.x and higher.
Functions version 1.x doesn't support isolated worker process. To use the isolated worker model, upgrade your application to Functions 4.x.
:::zone-end
This section describes the function app configuration settings available for functions that use this binding. These settings only apply when using extension version 5.0.0 and higher. The example host.json file below contains only the version 2.x+ settings for this binding. For more information about function app configuration settings in versions 2.x and later versions, see host.json reference for Azure Functions.
Note
This section doesn't apply to extension versions before 5.0.0. For those earlier versions, there aren't any function app-wide configuration settings for blobs.
{
"version": "2.0",
"extensions": {
"blobs": {
"maxDegreeOfParallelism": 4,
"poisonBlobThreshold": 1
}
}
}
Property | Default | Description |
---|---|---|
maxDegreeOfParallelism | 8 * (the number of available cores) | The integer number of concurrent invocations allowed for all blob-triggered functions in a given function app. The minimum allowed value is 1. |
poisonBlobThreshold | 5 | The integer number of times to try processing a message before moving it to the poison queue. The minimum allowed value is 1. |