How can I access the blob file inside the azure event grid trigger function?

Amey Pimpley 1 Reputation point
2020-10-21T23:40:28.357+00:00

I have a Event Grid Trigger Azure function to be triggered on blob getting uploaded in Azure Storage. I want to make some operations on that blob and save it in another storage container.
I want to access the the blob inside my Event Grid function, but getting error.

The way I have done this is:
public static async Task RunAsync(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Blob("{data.url}", Connection = "machinelogprd_STORAGE")]Stream myBlob,
ILogger log)
{
log.LogInformation(eventGridEvent.Data.ToString());

but I am getting below errors:

The type or namespace name 'BlobAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Blob' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'Connection' could not be found (are you missing a using directive or an assembly reference?)

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
379 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,426 Reputation points
    2020-10-22T14:27:30.13+00:00

    Hi @Amey Pimpley

    As per the error message looks like your function is unable to find the azure storage assembly. Can you refer to this document and install the storage extension.
    To access the blob inside within the event grid trigger you need to use storage SDK and write your own code to read the blob. Once you are done with the operation you can define the storage output binding that allows you to modify/delete the blob storage data. Make sure to review the Usage that will help you with supported bind types to write blobs.

    string connectionString = "yourconnectionstring";  
          
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);  
          
    blob = new CloudBlockBlob(new Uri(eventData.Url),storageAccount.Credentials);  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.