我将 plupload 与我的 ASP.NET MVC3 应用程序集成,具有以下设置:
var uploaderSettings = {
runtimes: "html5,silverlight,flash,html4",
browse_button: "browse-button",
container: "upload-ui",
drop_element: "drag-drop-area",
file_data_name: "file",
multiple_queues: true,
max_file_size: "10mb",
url: '@Url.Action("Index", "Upload")',
flash_swf_url: '@Url.Content("~/js/plupload/plupload.flash.swf")',
silverlight_xap_url: '@Url.Content("~/js/plupload.silverlight.xap")',
filters: [
{title: "Excel Files", extensions: "xls,xslx,csv"}
],
multipart: true,
urlstream_upload: true,
dragdrop: true,
multipart_params: {
token: "@AuthToken()"
}
};
plupload 从中生成 <input type="file">
在 accept
中包含以下项目属性(逗号分隔):
-
application/vnd.ms-excel
-
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
-
text/csv
在 Firefox 12.0 中,它忽略过滤器并允许选择任何文件类型。
在 Chrome 21 中,它不适用于提到的文件扩展名,但如果我将过滤器更改为图像文件(jpg、png、gif),它会正确过滤“选择文件”对话框。
我找到了 this issue在 Chromium 错误跟踪器上,这似乎是相关的,但在 2010 年 10 月被标记为已修复。
如果我将运行时优先级切换到 html5 以上的 silverlight 或 flash,它可以正常工作,但我宁愿不这样做,因为我失去了拖放文件上传功能。
这仅仅是浏览器对 accept 属性支持的限制,是我做错了什么,还是 plupload 中的错误?
更新:这似乎是一个 known issue ,归结为浏览器对 mime 类型过滤的支持。
最佳答案
听起来这不是验证文件类型的好方法。
accept attribute in input file is not working
仅用于提示操作系统在对话框中过滤文件类型。
当我使用 PL Upload 执行此操作时,我是基于扩展服务器端执行的。
关于html - 如何在 plupload HTML5 runtime 中过滤文件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10802681/