Azure Documentation

Blob Trigger

The Azure Functions Blob trigger starts a function in response to changes in Azure Blob Storage. This trigger is useful for processing data when a new blob is created or updated in a storage container.

How it works

The Blob trigger monitors a specified container in an Azure Storage account. When a new blob is uploaded or an existing blob is modified, the trigger activates your function. You can configure the trigger to listen for specific blob events, such as creation, or to process blobs as they appear.

Configuration

The Blob trigger requires a connection string to your Azure Storage account and a path to the container you want to monitor. The path can include wildcard characters to specify a subset of blobs or to include blob properties in the trigger.

Trigger Attribute (C# Example)


using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class ProcessBlob
{
    [FunctionName("BlobTriggerCSharp")]
    public static void Run(
        [BlobTrigger("samples-workitems/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob,
        string name,
        ILogger log)
    {
        log.LogInformation($"C# Blob trigger function processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        // Your logic to process the blob content goes here
    }
}
            

Trigger Configuration (function.json for JavaScript)


{
  "scriptFile": "index.js",
  "bindings": [
    {
      "name": "myBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "samples-workitems/{name}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}
            

Blob Path Patterns

You can use placeholders in the path to capture blob names and other properties. For example:

Connection Settings

The connection property in the trigger configuration specifies the name of the application setting that contains your Azure Storage account connection string. This is typically set to AzureWebJobsStorage, which is the default setting for Azure Functions.

Note: It is recommended to use the AzureWebJobsStorage setting to connect to your primary storage account. For other storage accounts, use individual connection strings defined in your application settings.

Best Practices

Common Scenarios

The Blob trigger provides a powerful and efficient way to integrate Azure Functions with Blob Storage, enabling event-driven processing of your data.