为什么Blueimp的JQuery文件上传添加所有的prev。即使在init中设置了选项[replaceFileInput:false]和[maxNumberOfFiles:1],也会选择文件? [英] Why Blueimp's JQuery File Upload add all prev. selected files even if options [replaceFileInput: false] and [maxNumberOfFiles: 1] are set on init?

查看:440
本文介绍了为什么Blueimp的JQuery文件上传添加所有的prev。即使在init中设置了选项[replaceFileInput:false]和[maxNumberOfFiles:1],也会选择文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有一些输入字段和一个文件输入字段的正常形式。
我使用Blueimp的Jquery File Upload插件来上传文件。这似乎工作,如果你选择一个文件,然后点击上传按钮。但是,如果您重新选择要上传的文件,它将保存所有的选择历史记录,上传后将所有的XHR发送到服务器。



我只想上传一个当前选定的文件,不是所有以前选择的文件(在文件打开对话框中)。

这是我的js模块来处理上传:


$ b $

  $(function(){
$('#upload_form')。fileupload({

dataType :'json',
autoUpload:false,
fileInput:'#filechose_button',
replaceFileInput:false,
maxNumberOfFiles:1,
multipart:true,

add:function(e,data){

$('#upload_button')。click(function(){

$('#upload_button ').attr('disabled',true);
...
data.submit();
...
});
},

完成:function(e,数据){
... //成功上传
},

progressall:function(e,data){
... //更新进度条
}
});
});

我在这里找到的解决方案(

maxNumberOfFiles:1 这个选项对我不起作用。

我有同样的问题,我的解决方案是解除绑定我的按钮的点击事件,并绑定它,每当添加事件被调用。试试这个。

...

  add:function(e ,数据){

$('#upload_button')。unbind('click');
data.context = $('#upload_button')。bind('click',function(){
...
data.submit();
}
}


I have just normal form with some input fields and one file input field. I use the Blueimp's Jquery File Upload plugin to upload a file. It seems to work, if you select a file and after that click the upload button. But if you reselect files to upload, it saves all the prehistory of selections and after upload sends all the XHRs to the server.

I want to upload only one currently selected file, not all the previously selected files (in file open dialog).

Here is my js module to handle the upload:

$(function () {
    $('#upload_form').fileupload({

        dataType: 'json',
        autoUpload: false,
        fileInput: '#filechose_button',
        replaceFileInput: false,
        maxNumberOfFiles: 1,
        multipart: true,

        add: function (e, data) {

            $('#upload_button').click(function () {

                $('#upload_button').attr('disabled', true);
                ...
                data.submit();
                ...
            });
        },

        done: function (e, data) {
          ... // successfully uploaded
        },

        progressall: function (e, data) {
          ... // update a progress bar
        }
    });
});

The solutions I found here (How to upload a file only once with blueimp file upload plugin?) seems to be not the best way (I see it as dirty), because just unbinding the click event still doesn't solve the problem of collecting all previously selected files (kind of memory leaks)

The option maxNumberOfFiles: 1 doesn't work for me.

解决方案

I had the same problem, my solution was to unbind the click event of my button and bind it back whenever the add event is called. Try This.

...

add: function (e, data) {

        $('#upload_button').unbind('click');
        data.context = $('#upload_button').bind('click', function () {
                    ...
                    data.submit();
        }
}

这篇关于为什么Blueimp的JQuery文件上传添加所有的prev。即使在init中设置了选项[replaceFileInput:false]和[maxNumberOfFiles:1],也会选择文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆