From a494b2e5e0e7754b01da02631c0ba4d944ae9210 Mon Sep 17 00:00:00 2001 From: pushrbx Date: Fri, 21 Jul 2017 11:12:26 +0100 Subject: [PATCH] added fixes to azure blob storage asset store --- .../Storage/AzureBlobAssetStore.cs | 7 +++++-- .../Storage/IStorageAccountManager.cs | 2 +- .../Storage/StorageAccountManager.cs | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs b/src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs index 993a63f48..506b38df2 100644 --- a/src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs +++ b/src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs @@ -65,7 +65,7 @@ namespace Squidex.Infrastructure.Azure.Storage var blob = blobContainer.GetBlockBlobReference(blobName); if (!await blob.ExistsAsync()) - return; + throw new AssetNotFoundException($"Asset {blobName} not found."); await blob.DownloadToStreamAsync(stream); } @@ -98,7 +98,10 @@ namespace Squidex.Infrastructure.Azure.Storage { try { - blobContainer = azureStorageAccount.GetContainer(containerName); + var task = azureStorageAccount.GetContainerAsync(containerName); + task.Wait(); + + blobContainer = task.Result; } catch (Exception) { diff --git a/src/Squidex.Infrastructure.Azure/Storage/IStorageAccountManager.cs b/src/Squidex.Infrastructure.Azure/Storage/IStorageAccountManager.cs index 259ac8028..43240316d 100644 --- a/src/Squidex.Infrastructure.Azure/Storage/IStorageAccountManager.cs +++ b/src/Squidex.Infrastructure.Azure/Storage/IStorageAccountManager.cs @@ -17,6 +17,6 @@ namespace Squidex.Infrastructure.Azure.Storage string GetSharedAccessSignature(); - CloudBlobContainer GetContainer(string name); + Task GetContainerAsync(string name); } } diff --git a/src/Squidex.Infrastructure.Azure/Storage/StorageAccountManager.cs b/src/Squidex.Infrastructure.Azure/Storage/StorageAccountManager.cs index e6ab77b9f..f09f105b8 100644 --- a/src/Squidex.Infrastructure.Azure/Storage/StorageAccountManager.cs +++ b/src/Squidex.Infrastructure.Azure/Storage/StorageAccountManager.cs @@ -45,10 +45,13 @@ namespace Squidex.Infrastructure.Azure.Storage }); } - public CloudBlobContainer GetContainer(string name) + public async Task GetContainerAsync(string name) { var blobClient = CreateCloudBlobClient(); - return blobClient.GetContainerReference(name); + var container = blobClient.GetContainerReference(name); + await container.CreateIfNotExistsAsync(); + + return container; } } } \ No newline at end of file