如何计算在dropzone中上传的所有文件大小? [英] How to calculate all files size uploaded in dropzone?
本文介绍了如何计算在dropzone中上传的所有文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算在dropzone中上传的所有选定文件的总大小.
I wanted to calculate all selected files total size uploaded in dropzone.
例如:如果我选择了5个文件,每个文件的大小为2mb,则 它应该返回10mb的总大小
Ex : if I selected 5 files each of size 2mb then it should return 10mb total size
我想限制所有文件的总大小是否超过限制.
I wanted to restrict if total size of all files is greater than limit.
有人可以帮我这个忙吗?
Can anyone please help me in this I am really stucked.
推荐答案
首先成功上传文件,然后遍历文件并获取文件大小. 如果总数超过一定限制,则可以在放置区上调用disable().
First get files uploaded successfully, then iterate through them and get size. You can then call disable() on the dropzone if the total exceeds a certain limit.
var files = dropzoneElement.getFilesWithStatus(Dropzone.SUCCESS), total=0;
$.each(files, function(file){
total+=file.size;
});
alert(total);
这篇关于如何计算在dropzone中上传的所有文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文