Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Blob storage trigger starts a function when a new or updated blob is detected. The blob contents are provided as input to the function.
Tip
There are several ways to execute your function code based on changes to blobs in a storage container. If you choose to use the Blob storage trigger, there are two implementations offered: a polling-based one (referenced in this article) and an event-based one. It is recommended that you use the event-based implementation as it has lower latency than the other. Also, the Flex Consumption plan supports only the event-based Blob storage trigger.
For details about differences between the two implementations of the Blob storage trigger, as well as other triggering options, see Working with blobs.
For information on setup and configuration details, see the overview.
Important
This article uses tabs to support multiple versions of the Node.js programming model. The v4 model is generally available and is designed to have a more flexible and intuitive experience for JavaScript and TypeScript developers. For more details about how the v4 model works, refer to the Azure Functions Node.js developer guide. To learn more about the differences between v3 and v4, refer to the migration guide.
Azure Functions supports two programming models for Python. The way that you define your bindings depends on your chosen programming model.
The Python v2 programming model lets you define bindings using decorators directly in your Python function code. For more information, see the Python developer guide.
This article supports both programming models.
For a complete end-to-end example of using the Blob Storage trigger, see Respond to blob storage events by using Azure Functions.
Example
A C# function can be created by using one of the following C# modes:
- Isolated worker model: Compiled C# function that runs in a worker process that's isolated from the runtime. Isolated worker process is required to support C# functions running on LTS and non-LTS versions .NET and the .NET Framework. Extensions for isolated worker process functions use
Microsoft.Azure.Functions.Worker.Extensions.*namespaces. - In-process model: Compiled C# function that runs in the same process as the Functions runtime. In a variation of this model, Functions can be run using C# scripting, which is supported primarily for C# portal editing. Extensions for in-process functions use
Microsoft.Azure.WebJobs.Extensions.*namespaces.
Important
Support will end for the in-process model on November 10, 2026. We highly recommend that you migrate your apps to the isolated worker model for full support.
The following example is a C# function that runs in an isolated worker process and uses a blob trigger with both blob input and blob output blob bindings. The function is triggered by the creation of a blob in the test-samples-trigger container. It reads a text file from the test-samples-input container and creates a new text file in an output container based on the name of the triggered file.
public static class BlobFunction
{
[Function(nameof(BlobFunction))]
[BlobOutput("test-samples-output/{name}-output.txt")]
public static string Run(
[BlobTrigger("test-samples-trigger/{name}")] string myTriggerItem,
[BlobInput("test-samples-input/sample1.txt")] string myBlob,
FunctionContext context)
{
var logger = context.GetLogger("BlobFunction");
logger.LogInformation("Triggered Item = {myTriggerItem}", myTriggerItem);
logger.LogInformation("Input Item = {myBlob}", myBlob);
// Blob Output
return "blob-output content";
}
}
This function uses a byte array to write a log when a blob is added or updated in the myblob container.
Polling-based:
The following example uses the default polling trigger:
@FunctionName("blobprocessor")
public void run(
@BlobTrigger(name = "file",
dataType = "binary",
path = "myblob/{name}",
connection = "MyStorageAccountAppSetting") byte[] content,
@BindingName("name") String filename,
final ExecutionContext context
) {
context.getLogger().info("Name: " + filename + " Size: " + content.length + " bytes");
}
The following example uses an Event Grid trigger:
@FunctionName("blobprocessor")
public void run(
@BlobTrigger(name = "file",
dataType = "binary",
path = "myblob/{name}",
source = "EventGrid",
connection = "MyStorageAccountAppSetting") byte[] content,
@BindingName("name") String filename,
final ExecutionContext context
) {
context.getLogger().info("Name: " + filename + " Size: " + content.length + " bytes");
}
This SDK types example uses BlobClient to access properties of the blob.
@FunctionName("processBlob")
public void run(
@BlobTrigger(
name = "content",
path = "images/{name}",
connection = "AzureWebJobsStorage") BlobClient blob,
@BindingName("name") String file,
ExecutionContext ctx)
{
ctx.getLogger().info("Size = " + blob.getProperties().getBlobSize());
}
This SDK types example uses BlobContainerClient to access info about blobs in the container that triggered the function.
@FunctionName("containerOps")
public void run(
@BlobTrigger(
name = "content",
path = "images/{name}",
connection = "AzureWebJobsStorage") BlobContainerClient container,
ExecutionContext ctx)
{
container.listBlobs()
.forEach(b -> ctx.getLogger().info(b.getName()));
}
This SDK types example uses BlobClient to get information from the input binding about the blob that triggered the execution.
@FunctionName("checkAgainstInputBlob")
public void run(
@BlobInput(
name = "inputBlob",
path = "inputContainer/input.txt") BlobClient inputBlob,
@BlobTrigger(
name = "content",
path = "images/{name}",
connection = "AzureWebJobsStorage",
dataType = "string") String triggerBlob,
ExecutionContext ctx)
{
ctx.getLogger().info("Size = " + inputBlob.getProperties().getBlobSize());
}
This example shows how to get the BlobClient from both a Storage Blob trigger and from the input binding on an HTTP trigger:
import "@azure/functions-extensions-blob"; // This is the mandatory first import for SDK binding
import { StorageBlobClient } from "@azure/functions-extensions-blob";
import { app, InvocationContext } from "@azure/functions";
export async function storageBlobTrigger(
blobStorageClient: StorageBlobClient, // SDK binding provides this client
context: InvocationContext
): Promise<void> {
context.log(`Blob trigger processing: ${context.triggerMetadata.name}`);
// Access to full SDK capabilities
const blobProperties = await blobStorageClient.blobClient.getProperties();
context.log(`Blob size: ${blobProperties.contentLength}`);
// Download blob content
const downloadResponse = await blobStorageClient.blobClient.download();
context.log(`Content: ${downloadResponse}`);
}
// Register the function
app.storageBlob("storageBlobTrigger", {
path: "snippets/{name}",
connection: "AzureWebJobsStorage",
sdkBinding: true, // Enable SDK binding
handler: storageBlobTrigger,
});
This example shows how to get the ContainerClient from both a Storage Blob input binding using an HTTP trigger:
import "@azure/functions-extensions-blob"; // This is the mandatory first import for SDK binding
import { StorageBlobClient } from "@azure/functions-extensions-blob";
import {
app,
HttpRequest,
HttpResponseInit,
input,
InvocationContext,
} from "@azure/functions";
const blobInput = input.storageBlob({
path: "snippets",
connection: "AzureWebJobsStorage",
sdkBinding: true,
});
export async function listBlobs(
request: HttpRequest,
context: InvocationContext
): Promise<HttpResponseInit> {
// Get input binding for a specific container
const storageBlobClient = context.extraInputs.get(
blobInput
) as StorageBlobClient;
// List all blobs in the container
const blobs = [];
for await (const blob of storageBlobClient.containerClient.listBlobsFlat()) {
blobs.push(blob.name);
}
return { jsonBody: { blobs } };
}
app.http("listBlobs", {
methods: ["GET"],
authLevel: "function",
extraInputs: [blobInput],
handler: listBlobs,
});
The following example shows a blob trigger TypeScript code. The function writes a log when a blob is added or updated in the samples-workitems container.
The string {name} in the blob trigger path samples-workitems/{name} creates a binding expression that you can use in function code to access the file name of the triggering blob. For more information, see Blob name patterns later in this article.
import { app, InvocationContext } from '@azure/functions';
export async function storageBlobTrigger1(blob: Buffer, context: InvocationContext): Promise<void> {
context.log(
`Storage blob function processed blob "${context.triggerMetadata.name}" with size ${blob.length} bytes`
);
}
app.storageBlob('storageBlobTrigger1', {
path: 'samples-workitems/{name}',
connection: 'MyStorageAccountAppSetting',
handler: storageBlobTrigger1,
});
The following example shows a blob trigger JavaScript code. The function writes a log when a blob is added or updated in the samples-workitems container.
The string {name} in the blob trigger path samples-workitems/{name} creates a binding expression that you can use in function code to access the file name of the triggering blob. For more information, see Blob name patterns later in this article.
const { app } = require('@azure/functions');
app.storageBlob('storageBlobTrigger1', {
path: 'samples-workitems/{name}',
connection: 'MyStorageAccountAppSetting',
handler: (blob, context) => {
context.log(
`Storage blob function processed blob "${context.triggerMetadata.name}" with size ${blob.length} bytes`
);
},
});
The following example demonstrates how to create a function that runs when a file is added to source blob storage container.
The function configuration file (function.json) includes a binding with the type of blobTrigger and direction set to in.
{
"bindings": [
{
"name": "InputBlob",
"type": "blobTrigger",
"direction": "in",
"path": "source/{name}",
"connection": "MyStorageAccountConnectionString"
}
]
}
Here's the associated code for the run.ps1 file.
param([byte[]] $InputBlob, $TriggerMetadata)
Write-Host "PowerShell Blob trigger: Name: $($TriggerMetadata.Name) Size: $($InputBlob.Length) bytes"
This example uses SDK types to directly access the underlying BlobClient object provided by the Blob storage trigger:
import azure.functions as func
import azurefunctions.extensions.bindings.blob as blob
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.blob_trigger(
arg_name="client", path="PATH/TO/BLOB", connection="AzureWebJobsStorage"
)
def blob_trigger(client: blob.BlobClient):
logging.info(
f"Python blob trigger function processed blob \n"
f"Properties: {client.get_blob_properties()}\n"
f"Blob content head: {client.download_blob().read(size=1)}"
)
For examples of using other SDK types, see the ContainerClient and StorageStreamDownloader samples. For a step-by-step tutorial on how to include SDK-type bindings in your function app, follow the Python SDK Bindings for Blob Sample.
To learn more, including what other SDK type bindings are supported, see SDK type bindings.
This example logs the blob name and size from the incoming blob trigger.
import logging
import azure.functions as func
app = func.FunctionApp()
@app.function_name(name="BlobTrigger1")
@app.blob_trigger(arg_name="myblob",
path="samples-workitems/{name}",
connection="MyStorageAccountAppSetting")
def test_function(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
The following example shows a Blob Storage trigger function that processes uploaded blobs:
package main
import (
"context"
"fmt"
"io"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"github.com/azure/azure-functions-golang-worker/sdk"
_ "github.com/azure/azure-functions-golang-worker/triggers/blob"
"github.com/azure/azure-functions-golang-worker/worker"
)
func main() {
app := sdk.FunctionApp()
app.Blob("blobTrigger", processBlob,
sdk.WithPath("samples-workitems/{name}"),
sdk.WithConnection("AzureWebJobsStorage"),
)
worker.Start(app)
}
func processBlob(ctx context.Context, client *blob.Client) error {
get, err := client.DownloadStream(ctx, nil)
if err != nil {
return fmt.Errorf("download error: %w", err)
}
data, _ := io.ReadAll(get.Body)
get.Body.Close()
log.Printf("Go Blob trigger function processed blob, %d bytes", len(data))
return nil
}
Note
The Blob trigger in Go provides an authenticated Azure SDK *blob.Client directly to your handler. You must add a blank import for triggers/blob to make the Blob trigger package available to the Go worker.
Attributes
Both in-process and isolated worker process C# libraries use the BlobAttribute attribute to define the function. C# script instead uses a function.json configuration file as described in the C# scripting guide.
The attribute's constructor takes the following parameters:
| Parameter | Description |
|---|---|
| BlobPath | The path to the blob. |
| Connection | The name of an app setting or setting collection that specifies how to connect to Azure Blobs. See Connections. |
| Access | Indicates whether you will be reading or writing. |
| Source | Sets the source of the triggering event. Use BlobTriggerSource.EventGrid for an Event Grid-based blob trigger, which provides lower latency. The default is BlobTriggerSource.LogsAndContainerScan, which uses the standard polling mechanism to detect changes in the container. |
Here's an BlobTrigger attribute in a method signature:
[Function(nameof(BlobFunction))]
[BlobOutput("test-samples-output/{name}-output.txt")]
public static string Run(
[BlobTrigger("test-samples-trigger/{name}")] string myTriggerItem,
[BlobInput("test-samples-input/sample1.txt")] string myBlob,
FunctionContext context)
When you're developing locally, add your application settings in the local.settings.json file in the Values collection.
Decorators
Applies only to the Python v2 programming model.
For Python v2 functions defined using decorators, the following properties on the blob_trigger decorator define the Blob Storage trigger:
| Property | Description |
|---|---|
arg_name |
Declares the parameter name in the function signature. When the function is triggered, this parameter's value has the contents of the queue message. |
path |
The container to monitor. May be a blob name pattern. |
connection |
The storage account connection string. |
source |
Sets the source of the triggering event. Use EventGrid for an Event Grid-based blob trigger, which provides lower latency. The default is LogsAndContainerScan, which uses the standard polling mechanism to detect changes in the container. |
For Python functions defined by using function.json, see the Configuration section.
Annotations
The @BlobTrigger attribute is used to give you access to the blob that triggered the function. Refer to the trigger example for details. Use the source property to set the source of the triggering event. Use EventGrid for an Event Grid-based blob trigger, which provides lower latency. The default is LogsAndContainerScan, which uses the standard polling mechanism to detect changes in the container. |
Configuration
Applies only to the Python v1 programming model.
The following table explains the properties that you can set on the options object passed to the app.storageBlob() method.
| Property | Description |
|---|---|
| path | The container to monitor. May be a blob name pattern. |
| connection | The name of an app setting or setting collection that specifies how to connect to Azure Blobs. See Connections. |
| source | Sets the source of the triggering event. Use EventGrid for an Event Grid-based blob trigger, which provides lower latency. The default is LogsAndContainerScan, which uses the standard polling mechanism to detect changes in the container. |
The following table explains the binding configuration properties that you set in the function.json file.
| function.json property | Description |
|---|---|
| type | Must be set to blobTrigger. This property is set automatically when you create the trigger in the Azure portal. |
| direction | Must be set to in. This property is set automatically when you create the trigger in the Azure portal. Exceptions are noted in the usage section. |
| name | The name of the variable that represents the blob in function code. |
| path | The container to monitor. May be a blob name pattern. |
| connection | The name of an app setting or setting collection that specifies how to connect to Azure Blobs. See Connections. |
| source | Sets the source of the triggering event. Use EventGrid for an Event Grid-based blob trigger, which provides lower latency. The default is LogsAndContainerScan, which uses the standard polling mechanism to detect changes in the container. |
See the Example section for complete examples.
Tip
For a complete working example that uses an Event Grid-based blob trigger with connection, source, and output binding configuration, see Respond to blob storage events using Azure Functions.
Metadata
The blob trigger provides several metadata properties. These properties can be used as part of binding expressions in other bindings or as parameters in your code. These values have the same semantics as the Cloud​Blob type.
| Property | Type | Description |
|---|---|---|
BlobTrigger |
string |
The path to the triggering blob. |
Uri |
System.Uri |
The blob's URI for the primary location. |
Properties |
BlobProperties | The blob's system properties. |
Metadata |
IDictionary<string,string> |
The user-defined metadata for the blob. |
The following example logs the path to the triggering blob, including the container:
public static void Run(string myBlob, string blobTrigger, ILogger log)
{
log.LogInformation($"Full blob path: {blobTrigger}");
}
Metadata
The blob trigger provides several metadata properties. These properties can be used as part of binding expressions in other bindings or as parameters in your code.
| Property | Description |
|---|---|
blobTrigger |
The path to the triggering blob. |
uri |
The blob's URI for the primary location. |
properties |
The blob's system properties. |
metadata |
The user-defined metadata for the blob. |
Metadata
Metadata is available through the $TriggerMetadata parameter.
Usage
The binding types supported by Blob trigger depend on the extension package version and the C# modality used in your function app.
The blob trigger can bind to the following types:
| Type | Description |
|---|---|
string |
The blob content as a string. Use when the blob content is simple text. |
byte[] |
The bytes of the blob content. |
| JSON serializable types | When a blob contains JSON data, Functions tries to deserialize the JSON data into a plain-old CLR object (POCO) type. |
| Stream1 | An input stream of the blob content. |
| BlobClient1, BlockBlobClient1, PageBlobClient1, AppendBlobClient1, BlobBaseClient1 |
A client connected to the blob. This set of types offers the most control for processing the blob and can be used to write back to the blob if the connection has sufficient permission. |
1 To use these types, you need to reference Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs 6.0.0 or later and the common dependencies for SDK type bindings.
Binding to string, or Byte[] is only recommended when the blob size is small. This is recommended because the entire blob contents are loaded into memory. For most blobs, use a Stream or BlobClient type. For more information, see Concurrency and memory usage.
If you get an error message when trying to bind to one of the Storage SDK types, make sure that you have a reference to the correct Storage SDK version.
You can also use the StorageAccountAttribute to specify the storage account to use. You can do this when you need to use a different storage account than other functions in the library. The constructor takes the name of an app setting that contains a storage connection string. The attribute can be applied at the parameter, method, or class level. The following example shows class level and method level:
[StorageAccount("ClassLevelStorageAppSetting")]
public static class AzureFunctions
{
[FunctionName("BlobTrigger")]
[StorageAccount("FunctionLevelStorageAppSetting")]
public static void Run( //...
{
....
}
The storage account to use is determined in the following order:
- The
BlobTriggerattribute'sConnectionproperty. - The
StorageAccountattribute applied to the same parameter as theBlobTriggerattribute. - The
StorageAccountattribute applied to the function. - The
StorageAccountattribute applied to the class. - The default storage account for the function app, which is defined in the
AzureWebJobsStorageapplication setting.
Note
Support for binding to SDK types is currently in preview and limited to the Azure Blob Storage SDK. For more information, see SDK types in the Java reference article.
Access the blob data via a parameter that matches the name designated by binding's name parameter in the function.json file.
Access blob data via the parameter typed as InputStream. Refer to the trigger example for details.
Functions also support Python SDK type bindings for Azure Blob storage, which lets you work with blob data using these underlying SDK types:
Note
Only synchronous SDK types are supported.
Important
SDK types support for Python is generally available and is only supported for the Python v2 programming model. For more information, see SDK types in Python.
Connections
The connection property is set to a key in application settings that returns a value used by the Functions runtime to connect to the storage account used by the extension. The value of the connection property setting depends on the type of connection:
- Managed identity connection: The
connectionproperty is a<CONNECTION_NAME_PREFIX>shared by a group of settings that together define an identity-based connection to the storage account. For more information, see Define identity connections. - Key Vault reference: The
connectionproperty setting returns an Azure Key Vault reference to the location where the connection string is centrally maintained. For more information, see Define Key Vault connections. - App Configuration reference: The
connectionproperty setting returns an Azure App Configuration reference that returns a connection string or a Key Vault reference. For more information, see Azure App Configuration in the connections article. - Connection string: The
connectionproperty setting returns the actual storage account connection string. Because the connection string contains shared secret keys, you should consider using a managed identity connection, when possible. For more information, see Define connections.
To learn more about bindings connections, see Manage connection in Azure Functions. To obtain a connection string, follow the steps shown at Manage storage account access keys.
When you set connection to a key or key prefix named AzureWebJobsStorage or to an empty string, the binding extension uses the default host storage account. For more information, see Optimize storage performance.
Blob name patterns
You can specify a blob name pattern in the path property in function.json or in the BlobTrigger attribute constructor. The name pattern can be a filter or binding expression. The following sections provide examples.
Tip
A container name can't contain a resolver in the name pattern.
Get file name and extension
The following example shows how to bind to the blob file name and extension separately:
"path": "input/{blobname}.{blobextension}",
If the blob is named original-Blob1.txt, the values of the blobname and blobextension variables in function code are original-Blob1 and txt.
Filter on blob name
The following example triggers only on blobs in the input container that start with the string "original-":
"path": "input/original-{name}",
If the blob name is original-Blob1.txt, the value of the name variable in function code is Blob1.txt.
Filter on file type
The following example triggers only on .png files:
"path": "samples/{name}.png",
Filter on curly braces in file names
To look for curly braces in file names, escape the braces by using two braces. The following example filters for blobs that have curly braces in the name:
"path": "images/{{20140101}}-{name}",
If the blob is named {20140101}-soundfile.mp3, the name variable value in the function code is soundfile.mp3.
Polling and latency
Polling works as a hybrid between inspecting logs and running periodic container scans. Blobs are scanned in groups of 10,000 at a time with a continuation token used between intervals. If your function app is on the Consumption plan, there can be up to a 10-minute delay in processing new blobs if a function app has gone idle.
Warning
Storage logs are created on a "best effort" basis. There's no guarantee that all events are captured. Under some conditions, logs may be missed.
If you require faster or more reliable blob processing, you should consider switching your hosting to use an App Service plan with Always On enabled, which may result in increased costs. You might also consider using a trigger other than the classic polling blob trigger. For more information and a comparison of the various triggering options for blob storage containers, see Trigger on a blob container.
Blob receipts
The Azure Functions runtime ensures that no blob trigger function gets called more than once for the same new or updated blob. To determine if a given blob version has been processed, it maintains blob receipts.
Azure Functions stores blob receipts in a container named azure-webjobs-hosts in the Azure storage account for your function app (defined by the app setting AzureWebJobsStorage). A blob receipt has the following information:
- The triggered function (
<FUNCTION_APP_NAME>.Functions.<FUNCTION_NAME>, for example:MyFunctionApp.Functions.CopyBlob) - The container name
- The blob type (
BlockBloborPageBlob) - The blob name
- The ETag (a blob version identifier, for example:
0x8D1DC6E70A277EF)
To force reprocessing of a blob, delete the blob receipt for that blob from the azure-webjobs-hosts container manually. While reprocessing might not occur immediately, it's guaranteed to occur at a later point in time. To reprocess immediately, the scaninfo blob in azure-webjobs-hosts/blobscaninfo can be updated. Any blobs with a last modified timestamp after the LatestScan property will be scanned again.
Poison blobs
When a blob trigger function fails for a given blob, Azure Functions retries that function a total of five times by default.
If all five tries fail, Azure Functions adds a message to a Storage queue named webjobs-blobtrigger-poison. The maximum number of retries is configurable. The same MaxDequeueCount setting is used for poison blob handling and poison queue message handling. The queue message for poison blobs is a JSON object that contains the following properties:
- FunctionId (in the format
<FUNCTION_APP_NAME>.Functions.<FUNCTION_NAME>) - BlobType (
BlockBloborPageBlob) - ContainerName
- BlobName
- ETag (a blob version identifier, for example:
0x8D1DC6E70A277EF)
Memory usage and concurrency
When you bind to an output type that doesn't support streaming, such as string, or Byte[], the runtime must load the entire blob into memory more than one time during processing. This can result in higher-than expected memory usage when processing blobs. When possible, use a stream-supporting type. Type support depends on the C# mode and extension version. For more information, see Binding types.
At this time, the runtime must load the entire blob into memory more than one time during processing. This can result in higher-than expected memory usage when processing blobs.
Memory usage can be further impacted when multiple function instances are concurrently processing blob data. If you are having memory issues using a Blob trigger, consider reducing the number of concurrent executions permitted. Reducing the concurrency can have the side effect of increasing the backlog of blobs waiting to be processed. The memory limits of your function app depend on the plan. For more information, see Service limits.
The way that you can control the number of concurrent executions depends on the version of the Storage extension you are using.
When using version 5.0.0 of the Storage extension or a later version, you control trigger concurrency by using the maxDegreeOfParallelism setting in the blobs configuration in host.json.
Limits apply separately to each function that uses a blob trigger.
host.json properties
The host.json file contains settings that control blob trigger behavior. See the host.json settings section for details regarding available settings.