33
44using System . IO ;
55using System . Threading . Tasks ;
6+ using Azure ;
67using Azure . Storage . Blobs ;
78using Azure . Storage . Blobs . Models ;
89using Microsoft . Extensions . Options ;
@@ -28,7 +29,6 @@ public AzureBlobStorageCache(IOptions<AzureBlobStorageCacheOptions> cacheOptions
2829 AzureBlobStorageCacheOptions options = cacheOptions . Value ;
2930
3031 this . container = new BlobContainerClient ( options . ConnectionString , options . ContainerName ) ;
31- this . container . CreateIfNotExistsAsync ( PublicAccessType . None ) ;
3232 }
3333
3434 /// <inheritdoc/>
@@ -56,5 +56,30 @@ public Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
5656
5757 return blob . UploadAsync ( stream , httpHeaders : headers , metadata : metadata . ToDictionary ( ) ) ;
5858 }
59+
60+ /// <summary>
61+ /// Creates a new container under the specified account if a container
62+ /// with the same name does not already exist.
63+ /// </summary>
64+ /// <param name="options">The Azure Blob Storage cache options.</param>
65+ /// <param name="accessType">
66+ /// Optionally specifies whether data in the container may be accessed publicly and
67+ /// the level of access. <see cref="PublicAccessType.BlobContainer"/>
68+ /// specifies full public read access for container and blob data. Clients can enumerate
69+ /// blobs within the container via anonymous request, but cannot enumerate containers
70+ /// within the storage account. <see cref="PublicAccessType.Blob"/>
71+ /// specifies public read access for blobs. Blob data within this container can be
72+ /// read via anonymous request, but container data is not available. Clients cannot
73+ /// enumerate blobs within the container via anonymous request. <see cref="PublicAccessType.None"/>
74+ /// specifies that the container data is private to the account owner.
75+ /// </param>
76+ /// <returns>
77+ /// If the container does not already exist, a <see cref="Response{T}"/> describing the newly
78+ /// created container. If the container already exists, <see langword="null"/>.
79+ /// </returns>
80+ public static Response < BlobContainerInfo > CreateIfNotExists (
81+ AzureBlobStorageCacheOptions options ,
82+ PublicAccessType accessType )
83+ => new BlobContainerClient ( options . ConnectionString , options . ContainerName ) . CreateIfNotExists ( accessType ) ;
5984 }
6085}
0 commit comments