1

由于 IE8 不支持 FormData(),我决定在我的 ASP Web 应用程序中试一下 jQuery File Upload,它似乎在 IE8 中可以工作,但是它并没有按照我的计划执行。

我正在使用该库的最新版本(我昨天更新),取自:https ://github.com/blueimp/jQuery-File-Upload

我在脚本包中有以下文件引用

"~/Scripts/jquery-file-upload/jquery.ui.widget.js",
"~/Scripts/jquery-file-upload/jquery.fileupload.js",
"~/Scripts/jquery-file-upload/jquery.fileupload-process.js",
"~/Scripts/jquery-file-upload/jquery.fileupload-ui.js",
"~/Scripts/jquery-file-upload/jquery.fileupload-validate.js",
"~/Scripts/jquery-file-upload/jquery.iframe-transport.js"

我还使用 Twitter Bootstrap 主题和 Knockout。当点击打开模态的按钮时触发以下函数,将库初始化为模态中的表单。

registerFileUpload: =>
    $("#target-form").fileupload(
        add: (e, data) =>
            data.context = $("#save-target-btn").click( ->
                data.submit()
            )
        done: (e, data) =>
            $("#add-new-target-modal").modal('hide')
        type: "POST"
        multipart: true
        url: "/route/to/save"
        maxNumberOfFiles: 1
        acceptFileTypes: /(\.|\/)(csv)$/i
    )
    .on('fileuploadadd', (e, data) ->
        appendTarget = $("#add-new-target-modal .modal-body")
        $.each(data.files, (index, file) ->
            $("#add-new-target-modal .modal-body").append("<span>" + file.name + "</span>");
        )
    )

我的问题是 maxNumberOfFiles 和 acceptFileTypes 似乎没有正确使用,即我仍然可以选择多个文件上传(我可以选择 2 个文件,它将作为单独的请求上传)和任何文件格式(我可以选择一个文件带有 .txt 扩展名)?

基本上,我只希望用户只能上传 1 个 .csv 文件。

4

0 回答 0