/// <summary> /// Initializes a new instance of the <see cref="AzureBlobStorageImageProvider"/> class. /// </summary> /// <param name="storageOptions">The blob storage options.</param> /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param> public AzureBlobStorageImageProvider( IOptions <AzureBlobStorageImageProviderOptions> storageOptions, FormatUtilities formatUtilities) { Guard.NotNull(storageOptions, nameof(storageOptions)); this.storageOptions = storageOptions.Value; this.formatUtilities = formatUtilities; this.storageAccount = CloudStorageAccount.Parse(this.storageOptions.ConnectionString); try { // It's ok to create a single reusable client since we are not altering it. CloudBlobClient client = this.storageAccount.CreateCloudBlobClient(); this.container = client.GetContainerReference(this.storageOptions.ContainerName); if (!this.container.Exists()) { this.container.Create(); this.container.SetPermissions(new BlobContainerPermissions { PublicAccess = this.storageOptions.AccessType }); } } catch (StorageException storageException) when(storageException.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict || storageException.RequestInformation.ExtendedErrorInformation.ErrorCode == StorageErrorCodeStrings.ContainerAlreadyExists) { // https://github.com/Azure/azure-sdk-for-net/issues/109 // We do not fire exception if container exists - there is no need in such actions } }
/// <summary> /// Initializes a new instance of the <see cref="AzureBlobStorageImageProvider"/> class. /// </summary> /// <param name="storageOptions">The blob storage options.</param> /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param> public AzureBlobStorageImageProvider( IOptions <AzureBlobStorageImageProviderOptions> storageOptions, FormatUtilities formatUtilities) { Guard.NotNull(storageOptions, nameof(storageOptions)); this.storageOptions = storageOptions.Value; this.formatUtilities = formatUtilities; this.container = new BlobContainerClient(this.storageOptions.ConnectionString, this.storageOptions.ContainerName); }
/// <summary> /// Initializes a new instance of the <see cref="AzureBlobStorageImageProvider"/> class. /// </summary> /// <param name="storageOptions">The blob storage options.</param> /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param> public AzureBlobStorageImageProvider( IOptions <AzureBlobStorageImageProviderOptions> storageOptions, FormatUtilities formatUtilities) { Guard.NotNull(storageOptions, nameof(storageOptions)); this.storageOptions = storageOptions.Value; this.formatUtilities = formatUtilities; this.storageAccount = CloudStorageAccount.Parse(this.storageOptions.ConnectionString); // It's ok to create a single reusable client since we are not altering it. CloudBlobClient client = this.storageAccount.CreateCloudBlobClient(); this.container = client.GetContainerReference(this.storageOptions.ContainerName); if (!this.container.Exists()) { this.container.Create(); this.container.SetPermissions(new BlobContainerPermissions { PublicAccess = this.storageOptions.AccessType }); } }