asp.net - 从 Kendo Upload 中排除文件类型
问题描述
我正在尝试设置 Kendo 上传验证。我可以将其设置为只接受列出的文件,但我想翻转它。我希望能够指定不允许的文件类型。例如,如果我想排除.exe
文件类型,我.exe
在代码中指定。
下面是我目前拥有的代码,它指定了允许的文件类型白名单;但我想使用黑名单进行验证。
@(Html.Kendo().Upload()
.Name("files")
.TemplateId("fileTemplate")
.HtmlAttributes(new { @class = "no-auto-save", AutoComplete = "off" })
.Async(a => a.Save("AddAttachments", "Transaction").AutoUpload(false))
.Events(e => e.Upload("uploadAttachments").Success("attachmentsUploaded"))
.Validation(validation => validation.AllowedExtensions(new string[] { ".doc", ".docx", ".ppt", ".pptx", ".xls", ".xlsx", ".jpg", ".jpeg", ".png", ".html", ".gif", "txt", ".pdf", ".json", ".zip" }))
)
解决方案
为事件添加处理程序upload
组件声明
.Events(events => events
.Upload("onUpload")
)
事件处理 JavaScript
function onUpload(e) {
if (e.files[0].extension == ".exe") {
e.preventDefault();
}
}
看
- https://docs.telerik.com/aspnet-mvc/api/Kendo.Mvc.UI.Fluent/UploadBuilder
- https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/events/upload
function onUpload(e) { // An array with information about the uploaded files var files = e.files; // Checks the extension of each file and aborts the upload if it is not .jpg $.each(files, function () { if (this.extension.toLowerCase() != ".jpg") { alert("Only .jpg files can be uploaded") e.preventDefault(); } });
推荐阅读
- android - 在 API 30 中为 resolveActivity 写入清单的意图操作
- react-native - 如何在本机反应中使用嵌套导航堆栈
- kubernetes - 如何使用 index.html 中的自定义文本在 nginx 上创建部署?
- json - 我如何能够比较两组 JSON 数据并检查一组是否在另一组中
- javascript - Async/Await:推理与实现
- javascript - 如何在javascript中将特定格式的日期转换为yyyy-mm-dd格式
- machine-learning - 使用 ML 识别 windows 计算机名称
- reactjs - 如何让 Accordion 行颜色在两种颜色之间交替?
- npm - 如何使用纱线工作区运行两个开发服务器?
- artificial-intelligence - 对象模式中未定义的类“command_data” - CLIPS