添加取消上传或中止功能以引导多个文件上传插件

Rah*_*pta 5 jquery file-upload twitter-bootstrap bootstrap-file-upload multiple-file-upload

我正在使用bootstrap多文件上传插件上传文件.我正在使用此链接上的示例.现在我想在"添加文件"按钮之外添加另一个按钮"取消上传".点击"取消上传"按钮后,应停止上传过程.请帮我解决这个问题.谢谢

Rah*_*pta 9

最后,经过大量的试验和错误以及搜索相关的代码解决方案之后,我才能按照我想要的方式工作!我在插件的github问题页面上发布了我的查询,并从那里得到了帮助.

下面是真正有效的代码示例:

1.首先,您必须绑定fileuploadadd事件:

$('#fileupload').bind('fileuploadadd', function(e, data){
      var jqXHR = data.submit(); // Catching the upload process of every file
      $('#cancel_all').on('click',function(e){
            jqXHR.abort();
      });
});
Run Code Online (Sandbox Code Playgroud)

2.然后,您必须绑定将在单击"取消上载"按钮时调用的取消事件,该按钮将取消当前正在上载的所有文件:

$('#fileupload').bind('fileuploadfail', function(e, data){
    if (data.errorThrown === 'abort')
    {
        //PUT HERE SOME FEEDBACK FOR THE USER
    }
});
Run Code Online (Sandbox Code Playgroud)