Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Created March 11, 2013 13:27
Show Gist options
  • Save shawnweisfeld/5134198 to your computer and use it in GitHub Desktop.
Save shawnweisfeld/5134198 to your computer and use it in GitHub Desktop.
Upload files to Azure Blobs FAST
ServicePointManager.DefaultConnectionLimit = 300;
var tempFolder = "Path To Folder Of Files You Want To Upload";
var cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ConnectionString"));
var blobClient = cloudStorageAccount.CreateCloudBlobClient();
List<Task> tasks = new List<Task>();
CloudBlobContainer toBlobContainer = blobClient.GetContainerReference("ContainerName");
toBlobContainer.CreateIfNotExist();
foreach (var fileName in Directory.GetFiles(tempFolder))
{
var toBlob = toBlobContainer.GetBlockBlobReference(fileName);
var stream = File.OpenRead(fileName);
var task = Task.Factory.FromAsync(toBlob.BeginUploadFromStream, toBlob.EndUploadFromStream, stream, null)
.ContinueWith(t =>
{
stream.Dispose();
});
tasks.Add(task);
}
Task.WaitAll(tasks.ToArray());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment