umbraco-community / UmbracoFileSystemProviders.Azure

:cloud: An Azure Blob Storage IFileSystem provider for Umbraco
96 stars 67 forks source link

Umbraco 8 and saving form data to the blob? #141

Closed jt3432 closed 5 years ago

jt3432 commented 5 years ago

Need a little help. I am using 2.0.0-alpha2 with Umbraco v8 and trying to get UmbracoForms Data to save to the blob as it did in v7, but not having any luck. I have added the below appSettings keys to my web.config in addition to the media appSettings keys:

What else am I missing? Media is saving to the blob fine. Thanks.

Jeavon commented 5 years ago

@jt3432 I think you forgot your keys. Anyhow, it is not within the scope of this package to support directly support UmbracoForms however you can use the AzureBlobFileSystem in your own Composer. Here is an example for UmbracoForms:

using Our.Umbraco.FileSystemProviders.Azure;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Forms.Core.Components;
using Umbraco.Forms.Data.FileSystem;
using Constants = Our.Umbraco.FileSystemProviders.Azure.Constants;

namespace MyNamespace
{
    [ComposeAfter(typeof(UmbracoFormsComposer))]
    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class AzureFormsFileSystemComposer: IComposer
    {
        private const string ProviderAlias = "forms";
        public void Compose(Composition composition)
        {
            var connectionString = ConfigurationHelper.GetAppSetting(Constants.Configuration.ConnectionStringKey, ProviderAlias);
            if (connectionString != null)
            {
                var config = CreateConfiguration();

                //Reads config from AppSetting keys
                composition.RegisterUnique(config);
                composition.RegisterUniqueFor<IFileSystem, FormsFileSystemForSavedData>(_ => new AzureBlobFileSystem(config));
            }
        }

        private AzureBlobFileSystemConfig CreateConfiguration()
        {
            var containerName = ConfigurationHelper.GetAppSetting(Constants.Configuration.ContainerNameKey, ProviderAlias);
            var rootUrl = ConfigurationHelper.GetAppSetting(Constants.Configuration.RootUrlKey, ProviderAlias);
            var connectionString = ConfigurationHelper.GetAppSetting(Constants.Configuration.ConnectionStringKey, ProviderAlias);
            var usePrivateContainer = ConfigurationHelper.GetAppSetting(Constants.Configuration.UsePrivateContainer, ProviderAlias);

            //Check we have all values set - otherwise make sure Umbraco does NOT boot so it can be configured correctly
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullOrEmptyException("containerName", $"The Azure File System is missing the value '{Constants.Configuration.ContainerNameKey}:{ProviderAlias}' from AppSettings");

            if (string.IsNullOrEmpty(rootUrl))
                throw new ArgumentNullOrEmptyException("rootUrl", $"The Azure File System is missing the value '{Constants.Configuration.RootUrlKey}:{ProviderAlias}' from AppSettings");

            if (string.IsNullOrEmpty(connectionString))
                throw new ArgumentNullOrEmptyException("connectionString", $"The Azure File System is missing the value '{Constants.Configuration.ConnectionStringKey}:{ProviderAlias}' from AppSettings");

            if (string.IsNullOrEmpty(usePrivateContainer))
                throw new ArgumentNullOrEmptyException("usePrivateContainer", $"The Azure File System is missing the value '{Constants.Configuration.UsePrivateContainer}:{ProviderAlias}' from AppSettings");

            return new AzureBlobFileSystemConfig
            {
                ContainerName = containerName,
                RootUrl = rootUrl,
                ConnectionString = connectionString,
                UsePrivateContainer = usePrivateContainer
            };
        }
    }
}

The add your own appsettings

    <add key="AzureBlobFileSystem.ContainerName:forms" value="forms-data" />
    <add key="AzureBlobFileSystem.RootUrl:forms" value="https://[account].blob.core.windows.net/" />
    <add key="AzureBlobFileSystem.ConnectionString:forms" value="DefaultEndpointsProtocol=https;AccountName=[account;AccountKey=[key];EndpointSuffix=core.windows.net" />
    <add key="AzureBlobFileSystem.UsePrivateContainer:forms" value="true" />
jt3432 commented 5 years ago

Thank you Jeavon for taking the time to reply. Greatly appreciated!!! :-) Yes, I did forget to add the keys. Mine look like the ones you provided, so I got the part right. I will try to implement the composer you provided. I think I understand what needs to be done now. Thank you again.