From 087fbd7f3cc80d083673d3873a1b43b815e4db86 Mon Sep 17 00:00:00 2001 From: Avinash Barnwal Home Date: Fri, 17 Jul 2020 21:50:01 +0530 Subject: [PATCH 1/3] Added Logging --- ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs index 17f565f..581f76c 100644 --- a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs +++ b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs @@ -88,7 +88,7 @@ public static async Task> GetThumbNailUrls(AzureStorageConfig _stor // 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. From e42998c9174baebd2a1690cc3818c109c9818000 Mon Sep 17 00:00:00 2001 From: Avinash Barnwal Home Date: Fri, 17 Jul 2020 21:51:51 +0530 Subject: [PATCH 2/3] Added Logging --- .../ImageResizeWebApp/Helpers/StorageHelper.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs index 581f76c..68cf8a7 100644 --- a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs +++ b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs @@ -57,15 +57,16 @@ public static async Task> GetThumbNailUrls(AzureStorageConfig _stor // 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); - + 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. @@ -99,6 +100,7 @@ public static async Task> GetThumbNailUrls(AzureStorageConfig _stor thumbnailUrls.Add(sasBlobUri); } } + return await Task.FromResult(thumbnailUrls); } } From e22759a10ff780794ee16fe2c7fb9129c4c5d2b8 Mon Sep 17 00:00:00 2001 From: Avinash Barnwal Home Date: Fri, 17 Jul 2020 22:53:19 +0530 Subject: [PATCH 3/3] Moving StorageSharedKeyCredential initialization before ServiceClient --- .../ImageResizeWebApp/Helpers/StorageHelper.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs index 68cf8a7..ee36e95 100644 --- a/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs +++ b/ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs @@ -55,11 +55,16 @@ 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); @@ -81,11 +86,7 @@ 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();