html - 如何在 plupload HTML5 runtime 中过滤文件类型?

标签 html firefox google-chrome file-upload plupload

我将 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/

相关文章:

javascript - 使用Turbo数据存储时如何添加innerHTML方面?

javascript - 如何禁止 Chrome 为我的 XMLHttpRequest 发出 "net::ERR_NAME_NOT_RESOLVED"?

css - 使用相同浏览器(chrome)在不同机器上显示不同的页面

javascript - Synergy 模板不会运行 &lt;script&gt; 代码

CSS div : margin:auto on vertical for IE7

php - 使用 javascript、表单和 php 发布和提交问题

css - Firefox svg 动画在特定 PC 上卡住

firefox - 无法删除 cookie - Firefox 拒绝过去的 cookie

firefox - 如何在启动 Selenium Remote Control 期间调整 Firefox 窗口大小/最大化?

apache-flex - Chrome Flash Player (Pepper) 日期 timezoneOffset 错误