对不起英文,我使用blueimp上传文件到我的项目,这一切都可以,但我不能限制文件的大小,不是一个而是他们的总和,在文档中有:
limitMultiFileUploadSize
The following option limits the number of files uploaded with one XHR request to keep the request size under or equal to the defined limit in bytes:
Type: integer
Default: undefined
Example: 1000000
Note: This option is ignored, if singleFileUploads is set to true.在我的项目中,我尝试插入:
<script>
ì$('#fileupload').fileupload({
singleFileUploads: false,
limitMultiFileUploadSize: 1000000 //1Mb
})
</script>但这不管用
然后我将部分代码添加到上传模板(带有注释//mycode的代码)
<!-- The template to display files available for upload -->
<script>var sizetotal=0;</script> //my code
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td>
<span class="preview"></span>
</td>
<td>
<p class="name">{%=file.name%}</p>
<strong class="error text-danger"></strong>
</td>
<td>
<p class="size">Processing...</p>
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
</td>
<td>
{% sizetotal=sizetotal+file.size;//my code
if(sizetotal>1000000){
alert('Puoi caricare al massimo un totale di un Mb i tuoi file superano questa dimensione')
}; //mycode %}
{% if (!i && !o.options.autoUpload && sizetotal<1000000) { %}
<button class="btn btn-primary start" disabled>
<i class="glyphicon glyphicon-upload"></i>
<span>Start</span>
</button>
{% } %}
{% if (!i) { %}
<button class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
{% } %}
</td>
</tr>
{%
} %}
</script>现在,如果大小文件的总和超过1Mb,就会出现警告,并且按钮被禁用,现在还有另一个问题,我如何减去我取消的文件大小?
油箱
发布于 2017-06-30 11:15:04
我也有同样的问题,并从源代码中得到了答案
https://blueimp.github.io/jQuery-File-Upload/js/main.js中有一个maxFileSize: 999000
这是我的代码
$('#fileupload').fileupload({
url: 'xxxx',
maxNumberOfFiles: 3, //Only can upload 3 files
acceptFileTypes: /(\.|\/)(JPG|JPEG|GIF|PNG)$/i, //Accept image
maxFileSize: 4000000, //Each file should under 4000000 bytes
singleFileUploads: false,
});https://stackoverflow.com/questions/41076852
复制相似问题