diff --git a/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs b/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs index e620478c220..c5a9fb2ba63 100644 --- a/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs +++ b/src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs @@ -50,6 +50,7 @@ public BlobFileStore(BlobStorageOptions options, IClock clock) try { await _blobContainer.CreateIfNotExistsAsync(); + await CreateBasePathIfNotExistsAsync(); await _blobContainer.SetPermissionsAsync(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob }); } catch (Exception ex) @@ -159,14 +160,13 @@ public async Task TryCreateDirectoryAsync(string path) if (await blob.ExistsAsync()) throw new FileStoreException($"Cannot create directory because the path '{path}' already exists and is a file."); - // Create a directory marker file to make this directory appear when - // listing directories. - var placeholderBlob = GetBlobReference(this.Combine(path, _directoryMarkerFileName)); - await placeholderBlob.UploadTextAsync("This is a directory marker file created by Orchard Core. It is safe to delete it."); + await CreateDirectoryAsync(path); return true; } + + public async Task TryDeleteFileAsync(string path) { await _verifyContainerTask; @@ -287,5 +287,29 @@ private CloudBlobDirectory GetBlobDirectoryReference(string path) return blobDirectory; } + + private async Task CreateDirectoryAsync(string path) + { + var placeholderBlob = GetBlobReference(this.Combine(path, _directoryMarkerFileName)); + + + // Create a directory marker file to make this directory appear when + // listing directories. + await placeholderBlob.UploadTextAsync( + "This is a directory marker file created by Orchard Core. It is safe to delete it."); + } + + private async Task CreateBasePathIfNotExistsAsync() + { + if (string.IsNullOrEmpty(_options.BasePath)) + return; + + var path = string.Empty; + var blob = GetBlobReference(path); + if (await blob.ExistsAsync()) + return; + + await CreateDirectoryAsync(path); + } } }