我正在使用CKFinder 3上传具有用户身份验证的文件。由于技术问题,我们没有配置文件,配置在代码中。现在我们必须能够上传带有特殊结尾* .template的文件,这些文件是包含CDATA部分中的html的XML文件。
默认情况下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 ......;});
确实编译但显然是错误的,因为文件无法上传。 这可能是一个初学者的问题,但我被困住了。我可以找到大量的示例来完成这里显示的内容但是我无法获得正确的关键字来在表达式中找到多个“参数”。 有人可以指出我做错了吗?
答案 0 :(得分:0)
我相信你要找的代码是:
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);
});
请注意,要上传文件,您还需要在templates
设置中添加xml
和allowedExtensions
个附加信息。
注意:如果您未指定AllowedExtensions
,则可以上传任何不安全的文件。