Posts

Showing posts with the label Blob Storage

Azure Blob Storage: How can I quickly read a text file?

My current project has the requirement to read a large text file from blob storage and then process the contents. Getting the file is easy: var storageAccount = CloudStorageAccount.Parse(CONNECTIONSTRING); var container = storageAccount.CreateCloudBlobClient().GetContainerReference(containerName); var blob =  container.GetBlobReference(fileName); And the data can be easily read: Stream stream = new MemoryStream(); blob.DownloadToStream(stream); stream.Position = 0; string text = ""; using (StreamReader reader = new StreamReader(stream)) { text = reader.ReadToEnd(); } var lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); The real time saver came when I had to process the contents. A traditional IEnumerable was too slow, but luckily Parallel saved the day: Parallel.For(0, lines.Length - 1, i => { DoSomethingWithTheRow(lines[i]); }); Its lightening fast. A word of warning: I passed a generic into the ...

Azure: How do I create an MVC site to load files to BLOB storage?

I recently created a simple POC site to load files to blob storage containers in Azure. Here is how I achieved it. My code is based on the sample provided  here After creating a simple MVC web project, I added the following nuget packages: DropZone WindowsAzure.Storage Microsoft.WindowsAzure.ConfigurationManager The code is pretty simple: Here is Index.cshtml: @model List<string> <script src="~/Scripts/dropzone/dropzone.min.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <link href="~/Scripts/dropzone/dropzone.min.css" rel="stylesheet" /> <div class="jumbotron">     <h2>FILE UPLOAD</h2>     <form action="~/Home/Upload"           class="dropzone"           id="dropzoneJsForm"           style="background-color:#00BFFF"></form>         <button id="refresh" onc...