Blob storage bindings for Azure Functions
Azure Functions can interact with Azure Blob Storage using input, output, and trigger bindings. These bindings let you read from or write to blobs without writing explicit storage‑client code.
Blob trigger
The blob trigger fires when a new blob is created or updated in a container.
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");
}
Use {name}
placeholder to capture the blob name in the function parameter.
Blob input
Bind a Stream
, byte[]
or POCO to read an existing blob.
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[Blob("samples-workitems/input.json", FileAccess.Read, Connection = "AzureWebJobsStorage")] Stream input,
ILogger log)
{
var json = await new StreamReader(input).ReadToEndAsync();
// process json
}
Blob output
Write data back to a blob by binding a out
parameter.
public static void Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
[Blob("samples-workitems/{rand-guid}.txt", FileAccess.Write, Connection = "AzureWebJobsStorage")] out string outputBlob,
ILogger log)
{
var body = new StreamReader(req.Body).ReadToEnd();
outputBlob = $"Received: {DateTime.UtcNow}\n{body}";
}
Full sample (C#)
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
public static class BlobTriggerCSharp
{
[FunctionName("BlobTriggerCSharp")]
public static void Run(
[BlobTrigger("input/{name}", Connection = "AzureWebJobsStorage")] Stream inputBlob,
string name,
[Blob("output/{name}", FileAccess.Write, Connection = "AzureWebJobsStorage")] Stream outputBlob,
ILogger log)
{
// simple copy
inputBlob.CopyTo(outputBlob);
log.LogInformation($"Blob {name} copied to output container.");
}
}
module.exports = async function (context, myBlob) {
const blobService = require('azure-storage').createBlobService(process.env.AzureWebJobsStorage);
const outputContainer = 'output';
const blobName = context.bindingData.name;
await new Promise((resolve, reject) => {
blobService.createBlockBlobFromStream(outputContainer, blobName, myBlob, myBlob.length, err => {
if (err) reject(err); else resolve();
});
});
context.log(`Blob ${blobName} copied to ${outputContainer} container.`);
};
Key concepts
- Connection string: Store in
AzureWebJobsStorage
app setting. - Path pattern: Use binding expressions (
{name}
,{queueTrigger}
) to capture values. - Access mode:
FileAccess.Read
,FileAccess.Write
, or default for trigger. - Scaling: Blob triggers scale out automatically based on the number of blobs.
Limitations & considerations
Aspect | Details |
---|---|
Blob size limit for trigger | Up to 4 GB (Azure Functions runtime limitation). |
Binding concurrency | Parallelism controlled by functions.workerProcessCount and host scaling. |
Eventual consistency | Blob trigger may have a slight delay (seconds) after upload. |
Authentication | Managed identity supported via IdentityConnection attribute. |
For detailed guidance, see the official documentation.