1

If I create an azure function Blob Trigger, I can define the both an input stream of the blob, and an output stream to which I would like to write some data, the signature being similar to below.

public async Task RunAsync(
            [BlobTrigger(BlobPath, Connection = "FileStorage")]
            Stream inputStream,
            [Blob(OutputBlobPath, FileAccess.Write, Connection = "FileStorage")]
            Stream outputStream,
            /* other fields removed for brevity */
            ) 
{ 
    /* ... */
}

Is it possible to define something similar when using an EventGrid trigger that fires for blob being created? i.e.

  public async Task RunAsync(
            [EventGridTrigger] EventGridEvent eventGridEvent, 
            [Blob("{data.url}", FileAccess.Read, Connection = "FileStorage")] Stream input,
/* is something like this possible -> */ [Blob(?, FileAccess.Write, Connection = "FileStorage")] Stream output)
        {
            /* ... */
        }

2 Answers 2

3

It's possible to bind to a CloudBlobContainer rather than a Stream for a blob, which provides the full storage API for blobs. It would look something like this:

public static async Task Run(
    [EventGridTrigger] EventGridEvent eventGridEvent,
    [Blob(/* container params */)] CloudBlobContainer blobContainer,
    ILogger log)
{
   // Use blobContainer to read/write blobs in container
}

From the Azure docs:

You can bind to the following types to write blobs:

TextWriter
out string
out Byte[]
CloudBlobStream
Stream
CloudBlobContainer
CloudBlobDirectory
ICloudBlob
CloudBlockBlob
CloudPageBlob
CloudAppendBlob
Sign up to request clarification or add additional context in comments.

1 Comment

I ended up going down this path, I ended up using the CludBlockBlob, and working backwards.
0

of course you can use output stream in EvenGrid Trigger Function. I test it locally. Firstly, I upload a blob named "input.txt" with the content "input". After run my function, I upload another blob (or delete another blob) to fire the trigger, then the content "input" is added to the blob named "test.txt".

Here is my code.

 [FunctionName("Function1")]
        public static async System.Threading.Tasks.Task RunAsync([EventGridTrigger] EventGridEvent eventGridEvent,
           [Blob("sample-items/input.txt", FileAccess.Read, Connection = "AzureWebJobsStorage")] Stream input,
           [Blob("sample-items/test.txt", FileAccess.Write, Connection = "AzureWebJobsStorage")] Stream output)
        {
            await input.CopyToAsync(output);
                    ......
         }

1 Comment

The issue is here is that I have dynamic path, meaning I have to using {data.url} as the blob path. Which I cannot manipulate to update the write path as you have. When you are using a blob trigger you can define a dynamic url with stuff like "a/{b}/" which as far as I can tell doesn't work with EventGridTriggers

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.