Created
March 11, 2013 13:27
-
-
Save shawnweisfeld/5134198 to your computer and use it in GitHub Desktop.
Upload files to Azure Blobs FAST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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