diff --git a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs index 17f565f..ee36e95 100644 --- a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs +++ b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs @@ -55,17 +55,23 @@ public static async Task> GetThumbNailUrls(AzureStorageConfig _stor { List thumbnailUrls = new List(); + // Create StorageSharedKeyCredentials object by reading + // the values from the configuration (appsettings.json) + StorageSharedKeyCredential storageCredential = + new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey); + // Create a URI to the storage account Uri accountUri = new Uri("https://" + _storageConfig.AccountName + ".blob.core.windows.net/"); - + Console.WriteLine(" Create BlobServiceClient from the account URI " + accountUri.ToString()); // Create BlobServiceClient from the account URI - BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri); - + BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri, storageCredential); + Console.WriteLine("Get reference to the container" + _storageConfig.ThumbnailContainer); // Get reference to the container BlobContainerClient container = blobServiceClient.GetBlobContainerClient(_storageConfig.ThumbnailContainer); - + if (container.Exists()) { + Console.WriteLine("Container Exists"); // Set the expiration time and permissions for the container. // In this case, the start time is specified as a few // minutes in the past, to mitigate clock skew. @@ -80,15 +86,11 @@ public static async Task> GetThumbNailUrls(AzureStorageConfig _stor sas.SetPermissions(BlobContainerSasPermissions.All); - // Create StorageSharedKeyCredentials object by reading - // the values from the configuration (appsettings.json) - StorageSharedKeyCredential storageCredential = - new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey); - + // Create a SAS URI to the storage account UriBuilder sasUri = new UriBuilder(accountUri); sasUri.Query = sas.ToSasQueryParameters(storageCredential).ToString(); - + Console.WriteLine(sasUri.ToString()); foreach (BlobItem blob in container.GetBlobs()) { // Create the URI using the SAS query token. @@ -99,6 +101,7 @@ public static async Task> GetThumbNailUrls(AzureStorageConfig _stor thumbnailUrls.Add(sasBlobUri); } } + return await Task.FromResult(thumbnailUrls); } }