A trigger starts an Azure Function; a binding connects it to data it needs to read or write. Input and output bindings expose connected resources through function parameters, avoiding boilerplate for those connections. A function has exactly one trigger, but it can use bindings for its other work. section 8.2.2 section 8.6
Resize an image and save the result
An HTTP-triggered function can read an NFT image from one Blob Storage container and write a smaller copy to another. Its input binding opens the original as a readable stream; its output binding supplies a writable stream. Image-resizing code still does the resizing—the bindings handle access to the blobs. section 8.2.2
[FunctionName("ProcessNFT")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Anonymous,
"get", "post", Route = "nft/{nftid}")] HttpRequest req, #1
[Blob("originalnfts/{nftid}", FileAccess.Read)]
Stream nftImage, #2
[Blob("copynfts/{nftid}", FileAccess.Write)]
Stream nftSmall) #3
{
IImageFormat format;
using (Image<Rgba32> input =
Image.Load<Rgba32>(nftImage, out format)) #4
{
input.Mutate(x => x.Resize(320, 200)); #5
input.Save(nftSmall, format); #6
}
}
The listing places an HTTP trigger and two Blob bindings on the function’s parameters. The input uses FileAccess.Read, the output uses FileAccess.Write, and the route’s {nftid} appears in both blob paths. section 8.2.2
Bindings can also be configured in the Azure portal. For a blob-triggered image function, add an Azure Blob Storage output, select the storage-account connection, name its parameter outputBlob, and set a destination such as imageoutputcontainer/{rand-guid}. The path places each resized image in the output container with a randomly generated GUID filename. The Integration view shows the resulting flow into and out of the function. section 2.2.19
Choose a binding for the resource interaction, not for the processing itself. Bindings can connect functions to inputs and outputs such as blobs, queues, or databases; the function code remains responsible for transforming the data. section 2.5 section 8.2.2
