如何在 CKFInder 中启用 HTML-Upload with Code-Configuration?

How to enable HTML-Upload with Code-Configuration in CKFInder?

我正在使用 CKFinder 3 通过用户身份验证上传文件。由于技术问题,我们没有配置文件,配置在代码中。现在我们必须能够上传具有特殊结尾 *.template 的文件,这些文件是 XML-CDATA 部分中包含 html 的文件。

CKFinder默认是拒绝的,所以我想用两个StringMatches“*.xml”和“*.template”扩展ResourceTypeBulder的SetAllowedHtmlExtensionMatchers。这是 SetupConnector

的代码
        OwinConnectorFactory connectorFactory = new OwinConnectorFactory();
        ConnectorBuilder connectorBuilder = new ConnectorBuilder();
        string l_licenseName = "DUMMY";
        string l_licenseKey = "DUMMY";
        connectorBuilder.SetLicense(l_licenseName, l_licenseKey); 
        connectorBuilder
            .SetAuthenticator(new CKFinderAuthenticator())
            .SetRequestConfiguration(
                (request, config) =>
                {
                    config.SetOverwriteOnUpload(true);
                    config.SetThumbnailSizes(new SizeAndQuality(100, 100, new ImageQuality(80))); 
                    config.AddProxyBackend("default", new LocalStorage(@""));
                    config.AddResourceType("MySite", resourceBuilder => resourceBuilder.SetBackend("default", ""));
                    config.AddAclRule(new AclRule(
                               new StringMatcher("*"),
                               new StringMatcher("*"),
                               new StringMatcher("*"),
                               new Dictionary<Permission, PermissionType> { { Permission.All, PermissionType.Allow } }));
                    var defaultBackend = config.GetBackend("default");
                    var keyValueStoreProvider = new FileSystemKeyValueStoreProvider(defaultBackend);
                    config.SetKeyValueStoreProvider(keyValueStoreProvider);
                    config.SetKeyValueStoreProvider(new EntityFrameworkKeyValueStoreProvider("MyConnection")));
                });
                app.UseConnector(connectorBuilder.Build(connectorFactory));

我必须扩展 resourceBuilder 以使用附加值,但我不知道如何做。 像

config.AddResourceType("MySite", resourceBuilder => {resourceBuilder.SetBackend("default", ""); resourceBuilder.SetAllowedHtmlExtensionMatchers ......;});

确实编译了,但显然是错误的,因为文件无法上传。 这可能是初学者的问题,但我被卡住了。我可以找到大量示例来完全执行此处显示的操作,但我无法获得正确的关键字以在表达式中找到多个 "parameter"。 有人可以指出我做错了什么吗?

我相信您要查找的代码是:

var allowedHtmlExtensions = new[] {
    new StringMatcher("template"),
    new StringMatcher("xml")
};

config.AddResourceType("Files", resourceBuilder => {
    resourceBuilder.SetBackend("default", "files");
    resourceBuilder.SetAllowedExtensions(new string[] { "template", "xml", "7z","aiff","asf","avi","bmp","csv","doc","docx","fla","flv","gif","gz","gzip","jpeg","jpg","mid","mov","mp3","mp4","mpc","mpeg","mpg","ods","odt","pdf","png","ppt","pptx","pxd","qt","ram","rar","rm","rmi","rmvb","rtf","sdc","sitd","swf","sxc","sxw","tar","tgz","tif","tiff","txt","vsd","wav","wma","wmv","xls","xlsx","zip" });
resourceBuilder.SetAllowedHtmlExtensionMatchers(allowedHtmlExtensions);
resourceBuilder.SetLazyLoaded(true);                            
});

请注意,要上传文件,您还需要在 allowedExtensions 设置中添加 templatesxml 扩展名。

注意:如果您不指定AllowedExtensions,则可以上传任何不安全的文件。