[英]jQuery File Upload - how to recognise when all files have uploaded
我正在使用 jQuery 文件上传插件。
我希望能够在所有选定的文件上传完成后触发一个事件。 到目前为止,我有一个事件,用于在选择要上传的文件以及当每个特定文件完成上传时执行操作 - 有没有办法检测到所有选定的文件都已完成上传?
实际的应用程序在这里http://repinzle-demo.herokuapp.com/upload
我的输入字段如下所示:
<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, function (index, file) {
$('<p/>').text("Upload complete ..."+file.name).appendTo("#fileList");
});
}
});
});
</script>
我正在使用如下所示的 Play Framework (Java) 控制器处理请求:
公开
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) {/* ... */})
如插件文档中所述:
上传停止回调,相当于全局ajaxStop事件(但仅针对文件上传请求)。
您还可以指定插件创建时将其作为参数传递的函数
$('#fileupload').fileupload({
stop: function (e) {}, // .bind('fileuploadstop', func);
});
这是您想要的解决方案:
$('#fileupload').on('fileuploaddone', function(e, data) { var activeUploads = $('#fileupload').fileupload('active'); if (activeUploads == 1) { console.info("All uploads done"); } });
我也有这个问题,3年前解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.