Azure Functions Documentation

Blob Output Binding

The Azure Blob Storage output binding for Azure Functions allows your function to write data to a blob container in Azure Blob Storage. This binding simplifies the process of storing output from your function directly into blob storage without needing to explicitly use the Azure Blob Storage SDK in your function code.

How it Works

When you configure a blob output binding, you specify the path and filename for the blob to be created or overwritten. The Azure Functions runtime handles the connection to your storage account and the writing of data to the specified blob.

Configuration

You configure bindings in your function's function.json file (for JavaScript, C#, Python, etc.) or using attributes in code (for C#, F#).

Example function.json:

{
  "bindings": [
    {
      "name": "inputQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "myqueue-items",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "outputBlob",
      "type": "blob",
      "direction": "out",
      "path": "output-container/{name}.txt",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

In this example:

Using the Binding in Code

Node.js Example:

index.js

module.exports = async function (context, inputQueueItem) {
    context.log('JavaScript queue trigger function processed work item', inputQueueItem);

    // Assuming inputQueueItem is a string or JSON object that can be serialized
    // If inputQueueItem is an object and you want to write it as JSON:
    // context.bindings.outputBlob = JSON.stringify(inputQueueItem, null, 2);

    // If you want to use a property from the input as part of the blob path:
    // For example, if inputQueueItem = { "name": "mydata", "content": "Some content here" }
    // and your function.json path is "output-container/{name}.txt"
    // The runtime automatically uses inputQueueItem.name if it exists.

    // For simple string output:
    context.bindings.outputBlob = `Data for ${inputQueueItem}: ${new Date().toISOString()}`;

    context.log(`Blob output written to ${context.bindingData.blobTrigger}`);
};

C# Example:

MyFunction.cs

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

public static class MyBlobOutputFunction
{
    [FunctionName("BlobOutputTrigger")]
    public static void Run(
        [QueueTrigger("myqueue-items")] string inputQueueItem,
        [Blob("output-container/{name}.txt", FileAccess.Write)] out string outputBlob,
        string name, // This 'name' parameter will be populated by the runtime based on the path token
        ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed work item: {inputQueueItem}");

        // Use the 'name' parameter from the trigger or path definition
        outputBlob = $"Processed data for item: {inputQueueItem} at {System.DateTime.UtcNow}";

        log.LogInformation($"Blob output written for name: {name}");
    }
}

Blob Path Customization

The path property in the binding configuration is powerful. You can use tokens to dynamically set the blob name and container based on the input trigger or other context.

Important: The blob output binding will create the specified blob if it doesn't exist. If the blob already exists, it will be overwritten by default. You can configure different behaviors if needed.

Supported Blob Types

The blob output binding supports writing various types:

Key Considerations