Azure Blob存储 - 将新文件上载到Blob容器

时间:2017-08-03 00:45:12

标签: azure azure-storage

在Azure中,我有一个存储帐户,用于从IoT设备上传文件。当IoT设备检测到某些条件时,将发送文件。所有文件都上传到同一个Blob容器和同一文件夹(在Blob容器内)。

我想要做的是在将新文​​件上传到Blob容器时自动发送电子邮件(作为警报)。我检查了Azure提供的不同选项,以便在存储帐户中设置警报(在Azure门户中),但我没有找到任何有用的信息。

我怎样才能创建这种警报?

1 个答案:

答案 0 :(得分:6)

据我所知,azure提供了天蓝色功能或webjobs,当新文件上传到特殊容器时可以触发。

我建议你可以使用azure function blob trigger来达到你的要求。 更多细节,您可以参考此article

在azure函数blob触发器触发方法中,您还可以绑定sendgrid以发送电子邮件。

更多细节,您可以参考以下步骤:

注意:我使用C#azure函数作为示例,您也可以使用其他语言。

1.创建一个blob触发器azure函数。

enter image description here

2.创建一个sendgrid(Link)帐户并创建API密钥。

enter image description here

3.Create设置创建的azure函数sendgrid outbind。

enter image description here

enter image description here

4.将以下代码添加到azure函数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;
}
相关问题