Skip to content

Commit cb625f5

Browse files
authored
Merge pull request #29 from umbraco/feature/createifnotexists
Add CreateIfNotExists helper method for Azure Blob Storage
2 parents 9c60661 + 870fec2 commit cb625f5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Umbraco.StorageProviders.AzureBlob/IO/AzureBlobFileSystem.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,5 +304,24 @@ private string GetBlobPath(string path)
304304
path = $"{_containerRootPath}/{path.TrimStart('/')}";
305305
return path.Trim('/');
306306
}
307+
308+
/// <summary>
309+
/// Creates a new container under the specified account if a container with the same name does not already exist.
310+
/// </summary>
311+
/// <param name="options">The Azure Blob Storage file system options.</param>
312+
/// <param name="accessType">Optionally specifies whether data in the container may be accessed publicly and the level of access.
313+
/// <see cref="PublicAccessType.BlobContainer" /> specifies full public read access for container and blob data. Clients can enumerate blobs within the container via anonymous request, but cannot enumerate containers within the storage account.
314+
/// <see cref="PublicAccessType.Blob" /> specifies public read access for blobs. Blob data within this container can be read via anonymous request, but container data is not available. Clients cannot enumerate blobs within the container via anonymous request.
315+
/// <see cref="PublicAccessType.None" /> specifies that the container data is private to the account owner.</param>
316+
/// <returns>
317+
/// If the container does not already exist, a <see cref="Response{T}" /> describing the newly created container. If the container already exists, <see langword="null" />.
318+
/// </returns>
319+
/// <exception cref="System.ArgumentNullException">options</exception>
320+
public static Response<BlobContainerInfo> CreateIfNotExists(AzureBlobFileSystemOptions options, PublicAccessType accessType = PublicAccessType.None)
321+
{
322+
if (options == null) throw new ArgumentNullException(nameof(options));
323+
324+
return new BlobContainerClient(options.ConnectionString, options.ContainerName).CreateIfNotExists(accessType);
325+
}
307326
}
308327
}

0 commit comments

Comments
 (0)