1

Is it possible to write an azure http trigger function with two output bindings, so that data not only outputs to an azure queue but also sends the same message to an azure blob storage?

3
  • 1
    yes, that's working. You can add many outbound bindings Commented Jun 3, 2022 at 10:58
  • 1
    Do you have any errors? Commented Jun 3, 2022 at 11:01
  • Can you please provide me with any links that explain it? Commented Jun 3, 2022 at 11:21

2 Answers 2

1

Please find a sample for multiple outbound bindings here:

    public async Task<IActionResult> Sample(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "sample")] HttpRequest req,
[Queue("sample", Connection = "StorageAccountString")] CloudQueue sampleQueue,
[Blob("sample", FileAccess.Read, Connection = "StorageAccountString")] CloudBlobContainer sampleContainer,
ExecutionContext context,
ILogger log)
    {
        var requestBody = await req.ReadAsStringAsync().ConfigureAwait(false);

        var queueMessage = new CloudQueueMessage(requestBody);
        await sampleQueue.AddMessageAsync(queueMessage).ConfigureAwait(false);

        CloudBlockBlob blob = sampleContainer.GetBlockBlobReference($"{Guid.NewGuid().ToString()}");
        blob.UploadText(requestBody);

        return new OkResult();
    }

Here you can find multiple Blob outbound bindings:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=in-process%2Cextensionv5&pivots=programming-language-csharp#example

**using System.Collections.Generic;
using System.IO;
using Microsoft.Azure.WebJobs;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

public class ResizeImages
{
    [FunctionName("ResizeImage")]
    public static void Run([BlobTrigger("sample-images/{name}")] Stream image,
        [Blob("sample-images-sm/{name}", FileAccess.Write)] Stream imageSmall,
        [Blob("sample-images-md/{name}", FileAccess.Write)] Stream imageMedium)
    {
        IImageFormat format;

        using (Image<Rgba32> input = Image.Load<Rgba32>(image, out format))
        {
            ResizeImage(input, imageSmall, ImageSize.Small, format);
        }

        image.Position = 0;
        using (Image<Rgba32> input = Image.Load<Rgba32>(image, out format))
        {
            ResizeImage(input, imageMedium, ImageSize.Medium, format);
        }
    }

    public static void ResizeImage(Image<Rgba32> input, Stream output, ImageSize size, IImageFormat format)
    {
        var dimensions = imageDimensionsTable[size];

        input.Mutate(x => x.Resize(dimensions.Item1, dimensions.Item2));
        input.Save(output, format);
    }

    public enum ImageSize { ExtraSmall, Small, Medium }

    private static Dictionary<ImageSize, (int, int)> imageDimensionsTable = new Dictionary<ImageSize, (int, int)>() {
        { ImageSize.ExtraSmall, (320, 200) },
        { ImageSize.Small,      (640, 400) },
        { ImageSize.Medium,     (800, 600) }
    };

}**
Sign up to request clarification or add additional context in comments.

Comments

0

If you're running your function app in an isolated process, Microsoft has a brief discussion and example here:

Isolated process - Multiple output bindings

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.