Closed ronaldbarendse closed 2 years ago
Note that when creating the container in the Action<AzureBlobFileSystemOptions>
configure callback, this will also be executed during runtime, but for each time an IOptions<AzureBlobFileSystemOptions>
is requested from the DI container (which might result in calling this multiple times during the lifetime of the application).
So use the following with caution:
.AddAzureBlobMediaFileSystem(options => {
options.ConnectionString = "";
options.ContainerName = "";
AzureBlobFileSystem.CreateIfNotExists(options);
})
This closes https://github.com/umbraco/Umbraco.StorageProviders/issues/6 by allowing you to (more easily) create the container if it doesn't exist yet (you need to explicitly opt-in, because it requires create/write permissions, does a service request and you need to specify the access type, see Azure Storage Blobs-azure-storage-blobs-models-blobcontainerencryptionscopeoptions-system-threading-cancellationtoken))/legacy docs).
I've not added this as an extra option to
AzureBlobFileSystemOptions
, because the creation should be done only once during runtime (so not during configuration) and also not within theAzureBlobFileSystem
constructor. It's still best practice to ensure the configured container is already created, but this might make development/testing a bit easier.The following code should automatically create the container on application startup: