The Azure Blob Storage trigger allows a function to be executed when a new or updated blob is detected in a specified Azure Blob Storage container.
Key Concept: This trigger is designed for event-driven processing of blob data. When a blob changes in the configured storage account and container, your function is automatically invoked.
The blob trigger monitors a specific container in your Azure Blob Storage account. When a blob is added or updated in that container, the Azure Functions runtime detects the change and invokes your function. The trigger provides the blob content and metadata to your function.
The blob trigger is defined in your function's function.json file (for JavaScript and Python) or using attributes in your code (for C#).
This example shows a function triggered by changes in a blob container named samples-workitems.
{
"scriptFile": "index.js",
"bindings": [
{
"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/{name}",
"connection": "AzureWebJobsStorage"
}
]
}
In C#, you use the BlobTrigger attribute:
using Microsoft.Azure.WebJobs;
public static class BlobTriggerFunction
{
[FunctionName("BlobTriggerCSharp")]
public static void Run(
[BlobTrigger("samples-workitems/{name}")] Stream myBlob,
string name)
{
// Function logic here
System.Diagnostics.Trace.WriteLine($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
}
The following table describes the common properties for the blob trigger binding:
| Property | Description | Required | Type |
|---|---|---|---|
name |
The name of the parameter in your function that will receive the blob data. | Yes | String |
type |
Must be set to blobTrigger. |
Yes | String |
direction |
Must be set to in for a trigger. |
Yes | String |
path |
The container and blob path to monitor. You can use wildcards (e.g., samples-workitems/{name}, logs/{year}/{month}/{day}/{name}.txt). The {name} part is a placeholder for the blob name and can be used to pass the blob name to your function. |
Yes | String |
connection |
The name of an app setting that contains the connection string for the storage account. If omitted, the AzureWebJobsStorage app setting is used by default. |
No | String |
dataType |
Specifies the data type of the blob content. Common values include string, byte[], Stream, or inferred from the function signature. |
No | String |
In addition to the blob content, you can access various metadata properties. The available metadata depends on the language and how the binding is defined.
The name parameter in function.json corresponds to the blob name. Other metadata can be accessed via the context object.
module.exports = async function (context, myBlob) {
context.log("JavaScript blob trigger function processed blob");
context.log("Name:", context.bindingData.name);
context.log("Blob Size:", myBlob.length, "Bytes");
context.log("Content Type:", context.bindingData.properties.contentType);
context.log("Last Modified:", context.bindingData.properties.lastModified);
};
In C#, you can bind to metadata properties by adding parameters to your function signature that match the metadata names (e.g., name, lastModified, eTag).
using Microsoft.Azure.WebJobs;
using System.IO;
using System;
public static class BlobTriggerMetadata
{
[FunctionName("BlobTriggerMetadata")]
public static void Run(
[BlobTrigger("samples-workitems/{name}")] Stream myBlob,
string name,
DateTime lastModified,
string contentType,
string eTag)
{
System.Diagnostics.Trace.WriteLine($"C# Blob trigger function Processed blob");
System.Diagnostics.Trace.WriteLine($"Name: {name}");
System.Diagnostics.Trace.WriteLine($"Blob Size: {myBlob.Length} Bytes");
System.Diagnostics.Trace.WriteLine($"Last Modified: {lastModified}");
System.Diagnostics.Trace.WriteLine($"Content Type: {contentType}");
System.Diagnostics.Trace.WriteLine($"ETag: {eTag}");
}
}
The path property in the binding configuration is powerful and supports various patterns:
mycontainer/{name}mycontainer/folder/{name}logs/{year}/{month}/{day}/{name}.txtsamples-workitems/*.csv (triggers for any blob ending in .csv in the samples-workitems container)The values captured in the path (e.g., {name}, {year}) are made available as binding data.
Best Practice: For high-traffic containers, consider using date-based partitioning in your path (e.g., mycontainer/{year}/{month}/{day}/{name}) to improve trigger performance and manageability.
connection property (or the default AzureWebJobsStorage) is correctly configured in your function app's application settings.