Azure Functions Documentation

Blob storage bindings

Azure Functions provides seamless integration with Azure Blob storage using input and output bindings. This page explains how to work with blobs in your functions.

Input binding

Read the content of a blob as a string, byte[], Stream, or a custom POCO.

{
  "type": "blob",
  "direction": "in",
  "name": "inputBlob",
  "path": "samples/{name}",
  "connection": "AzureWebJobsStorage"
}

Example (C#):

public static void Run(
    [BlobTrigger("samples/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob,
    string name,
    ILogger log)
{
    using var reader = new StreamReader(myBlob);
    var content = reader.ReadToEnd();
    log.LogInformation($"Blob {name} contents: {content}");
}

Output binding

Write data to a blob as part of the function execution.

{
  "type": "blob",
  "direction": "out",
  "name": "outputBlob",
  "path": "output/{name}",
  "connection": "AzureWebJobsStorage"
}

Example (JavaScript):

module.exports = async function (context, req) {
    const name = req.query.name || (req.body && req.body.name);
    if (name) {
        context.bindings.outputBlob = `Hello ${name}!`;
        context.res = { status: 200, body: "Blob written." };
    } else {
        context.res = { status: 400, body: "Please provide a name." };
    }
};

Binding attributes per language

LanguageInput attributeOutput attribute
C#[BlobTrigger][Blob]
JavaScriptcontext.bindings.inputBlobcontext.bindings.outputBlob
Pythoninputblob: func.InputStreamoutputblob: func.Out[str]
PowerShell$TriggerInput$OutputBlob

Best practices

References