Blob trigger binding

The Blob trigger allows Azure Functions to react to changes in Azure Blob Storage. A function with a Blob trigger is invoked each time a new blob is added or an existing blob is updated in the specified container.

When to use

Function signature

public static void Run(
    [BlobTrigger("samples-workitems/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob,
    string name,
    ILogger log)

Configuration

pathPattern that identifies the container and blob name. Use {name} to capture the blob name.
connectionName of the app setting containing the storage account connection string.
cardinalitymany or one – determines whether the trigger receives a single blob or a batch.

Sample function

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

public static class BlobTriggerSample
{
    [FunctionName("BlobTriggerSample")]
    public static void Run(
        [BlobTrigger("input/{filename}", Connection = "AzureWebJobsStorage")] Stream blob,
        string filename,
        ILogger log)
    {
        log.LogInformation($"Blob trigger processed file: {filename}, Size: {blob.Length} bytes");
        // Add your processing logic here
    }
}

Local development

  1. Install the Azure Functions Core Tools.
  2. Set AzureWebJobsStorage in local.settings.json to your storage emulator or account.
  3. Run func start and upload a blob to the defined container.

Related topics