in Hands-on lab/lab-files/src/TollBooth/UploadImages/Program.cs [45:102]
private static void UploadImages(bool upload1000)
{
Console.WriteLine("Uploading images");
int uploaded = 0;
// Setup the number of the concurrent operations.
BlobUploadOptions options = new BlobUploadOptions
{
TransferOptions = new Azure.Storage.StorageTransferOptions
{
MaximumConcurrency = 64
}
};
// Set ServicePointManager.DefaultConnectionLimit to the number of eight times the number of cores.
ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 8;
ServicePointManager.Expect100Continue = false;
// Setup the transfer context and track the upload progress.
//var context = new SingleTransferContext
//{
// ProgressHandler =
// new Progress<TransferStatus>(
// (progress) => { Console.WriteLine("Bytes uploaded: {0}", progress.BytesTransferred); })
//};
if (upload1000)
{
LoadImagesFromDisk(true);
for (var i = 0; i < 200; i++)
{
foreach (var image in _sourceImages)
{
// Rewind the memory stream
image.Position = 0;
var filename = GenerateRandomFileName();
var blobBlockClient = new BlockBlobClient(BlobStorageConnection, "images", filename);
var task = blobBlockClient.UploadAsync(image, options);
task.Wait();
uploaded++;
Console.WriteLine($"Uploaded image {uploaded}: {filename}");
}
}
}
else
{
LoadImagesFromDisk(false);
foreach (var image in _sourceImages)
{
var filename = GenerateRandomFileName();
var blobBlockClient = new BlockBlobClient(BlobStorageConnection, "images", filename);
var task = blobBlockClient.UploadAsync(image, options);
task.Wait();
uploaded++;
Console.WriteLine($"Uploaded image {uploaded}: {filename}");
}
}
Console.WriteLine("Finished uploading images");
}