Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Blob Storage - Set an alert when a new file is uploaded to a specific folder in a blob container

In Azure, I have a Storage Account that I use to upload files from an IoT device. The files are sent when the IoT device detects certain conditions. All the files are uploaded to the same Blob Container and in the same folder (inside the Blob container).

What I would like to do is to send an email automatically (as an alert) when a new file is uploaded to the Blob Container. I have checked the different options that are provided by Azure to set alerts in Storage accounts (in Azure Portal) but I have not found anything useful.

How could I create this kind of alert?

like image 295
John Mitchell Avatar asked Jan 29 '23 21:01

John Mitchell


1 Answers

As far as I know, the azure provides the azure function or webjobs which could be triggered when the new files uploaded to the special container.

I suggest you could use azure function blob trigger to achieve your requirement. More details, you could refer to this article.

In the azure function blob trigger fired method you could also bind sendgrid to send the email.

More details, you could refer to below steps:

Notice: I used C# azure function as example, you could also use another language.

1.Create a blob trigger azure function.

enter image description here

2.Create a sendgrid(Link) account and create API key.

enter image description here

3.Create set the created azure function sendgrid outbind.

enter image description here

enter image description here

4.Add below codes to azure function run.csx.

#r "SendGrid"
using System;
using SendGrid;
using SendGrid.Helpers.Mail;



public static Mail Run(Stream myBlob, string name, TraceWriter log)
{
    var  message = new Mail
    {        
        Subject = "Azure news"          
    };

    var personalization = new Personalization();
    personalization.AddTo(new Email("sendto email address"));   

    Content content = new Content
    {
        Type = "text/plain",
        Value = name
    };
    message.AddContent(content);
    message.AddPersonalization(personalization);

    return message;
}
like image 134
Brando Zhang Avatar answered Feb 02 '23 10:02

Brando Zhang