我正在使用jQuery文件上传插件.
当所有选定的文件完成上传时,我想要触发一个事件.到目前为止,我有一个事件做一个动作,当选择一个文件上传和每个特定的文件完成上传 – 有没有办法检测所有选定的文件已完成上传?@H_301_3@
实际的应用程序在这里是http://repinzle-demo.herokuapp.com/upload@H_301_3@
我的输入字段如下所示:@H_301_3@
<div id="fine-uploader-basic" class="btn btn-success" style="position: relative; overflow: hidden; direction: ltr;">
<script> $(function () { $('#fileupload').fileupload({ dataType: 'json',add: function (e,data) { // when files are selected this lists the files to be uploaded $.each(data.files,function (index,file) { $('<p/>').text("Uploading ... "+file.name).appendTo("#fileList"); }); data.submit(); },done: function (e,data) { // when a file gets uploaded this lists the name $.each(data.files,file) { $('<p/>').text("Upload complete ..."+file.name).appendTo("#fileList"); }); } }); }); </script>
我正在使用如下的Play Framework(Java)控制器来处理请求:@H_301_3@
公共区域@H_301_3@
c static void doUpload(File[] files) throws IOException{ List<ImageToUpload> imagesdata = new ArrayList<ImageToUpload>(); //ImageToUpload has information about images that are going to be uploaded,name size etc. for(int i=0;i<files.length;i++){ Upload upload = new Upload(files[i]); upload.doit(); //uploads pictures to Amazon S3 Picture pic = new Picture(files[i].getName()); pic.save(); // saves Metadata to a MongoDB instance imagesdata.add(new ImageToUpload(files[i].getName())); } renderJSON(imagesdata); }
解决方法
我想你正在寻找“停止”事件:
$('#fileupload').bind('fileuploadstop',function (e) {/* ... */})
如plugin documentation所说:@H_301_3@
Callback for uploads stop,equivalent to the global ajaxStop event
(but for file upload requests only).@H_301_3@
$('#fileupload').fileupload({ stop: function (e) {},// .bind('fileuploadstop',func); });