Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions ImageResizeWebApp/ImageResizeWebApp/Helpers/StorageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,23 @@ public static async Task<List<string>> GetThumbNailUrls(AzureStorageConfig _stor
{
List<string> thumbnailUrls = new List<string>();

// 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.
Expand All @@ -80,15 +86,11 @@ public static async Task<List<string>> 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.
Expand All @@ -99,6 +101,7 @@ public static async Task<List<string>> GetThumbNailUrls(AzureStorageConfig _stor
thumbnailUrls.Add(sasBlobUri);
}
}

return await Task.FromResult(thumbnailUrls);
}
}
Expand Down