Question:
A company requires a function that can process incoming files automatically. They upload images regularly into a storage service, and they want those images to be resized automatically. Which Azure service could you use to trigger this function? Fill in the triggers and bindings in the following code:
[FunctionName("ResizeImage")]
public static void Run(
/* Triggers and Bindings here */
string name,
ILogger log)
{
// Read the input image
// Resize the image
// Write the resized image to output image
}
Answer:
This scenario is perfect for a Blob Storage trigger. The function could be triggered whenever a new blob (image) is added to the Blob Storage. Inside the function, you could use an image processing library to resize the images.
[FunctionName("ResizeImage")]
public static void Run(
[BlobTrigger("<container-name>/{name}", Connection = "BlobStorageConnectionString")]
Stream inputImage,
[Blob("<container-name>/{name}", FileAccess.Write, Connection = "BlobStorageConnectionString")]
Stream outputImage,
string name,
ILogger log)
{
// Read the input image
// Resize the image
// Write the resized image to output image
}