我想在Microsoft Azure中查找一个存储帐户,列出特定容器(在存储帐户中)中的blob,然后将列出的blob名称存储到数据库表中.任何人都建议使用C#代码将Blob名称列表存储到数据库表中.
I want to lookup a storage account in Microsoft Azure, list the blobs in a particular container(in the storage account),then store the listed blob names to a database table. Anyone please suggest a c# code to store the list of blob names to database table.
namespace ListStorageAccntFiles { class Program { static void Main(string[] args) { Console.Clear(); //Code to list the blobnames in Console CloudStorageAccount StorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); var BlobClient = StorageAccount.CreateCloudBlobClient(); var Container = BlobClient.GetContainerReference("samples-workitems"); var list = Container.ListBlobs(); List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name).ToList(); blobNames.ForEach(Console.WriteLine); //Code to store blobnames under the column header "name" in a database table } } }推荐答案
与方案!!!该程序可以查看存储帐户并处理所有新的&修改的文件,如果有新文件,请采取措施
with the scenario!!!! program that can look at storage account and process all new & modified files and take an action if there is any new ones
我认为,我建议使用WebJobs SDK的BlobTrigger来实现您的目的.以下是我的代码示例,您可以更好地了解它:
In my opinion, I recommend using BlobTrigger of WebJobs SDK to achieve your purpose.Here is my code sample for you to have a better understanding of it:
WebJob班
public class Functions { //This function will get triggered/executed when a blob is created or updated on an Azure Blob container called trigger-blob-input. public static void TriggerAzureBlob([BlobTrigger("trigger-blob-input/{name}")] ICloudBlob blob) { Console.WriteLine("Blob name:" + blob.Name); //do something with the created/updated blob } }
按以下步骤创建/更新Blob时:
When blobs are created/updated as follows:
您可以通过BlobTrigger检测到blob,并获得以下输出:
You could detect the blobs via BlobTrigger and get the following output:
有关更多详细信息,您可以参考以下教程:
For more details, you could refer to the following tutorials:
如何创建和部署WebJob到Azure
如何在blob上触发函数创建或更新
此外,WebJobs SDK扫描日志文件以监视新的或更改的Blob.此过程不是读取时间,因此在创建/更新Blob之后,可能不会在短时间内或更长时间内触发功能.
Additionally, the WebJobs SDK scans log files to monitor new or changed blobs. This process is not read-time, so a function might not be triggered for a short or longer time after the blob is created/updated.
如果Blob触发器的限制不满足您的应用程序的要求,则可以在创建/更新Blob时创建队列消息,然后使用 QueueTrigger 而不是处理Blob的函数上的BlobTrigger.
If the limitation of blob trigger is not meet your application, you could create a queue message when you create/update the blob, then use the QueueTrigger instead of BlobTrigger on the function that processes your blob.
更多推荐
存储列表< string>到SQL数据库表?
发布评论