首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >blueimp limitMultiFileUploadSize

blueimp limitMultiFileUploadSize
EN

Stack Overflow用户
提问于 2016-12-10 22:55:41
回答 1查看 347关注 0票数 0

对不起英文,我使用blueimp上传文件到我的项目,这一切都可以,但我不能限制文件的大小,不是一个而是他们的总和,在文档中有:

代码语言:javascript
复制
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.

在我的项目中,我尝试插入:

代码语言:javascript
复制
<script>
ì$('#fileupload').fileupload({ 
  singleFileUploads: false,   
  limitMultiFileUploadSize: 1000000  //1Mb


})

</script>

但这不管用

然后我将部分代码添加到上传模板(带有注释//mycode的代码)

代码语言:javascript
复制
<!-- 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,就会出现警告,并且按钮被禁用,现在还有另一个问题,我如何减去我取消的文件大小?

油箱

EN

回答 1

Stack Overflow用户

发布于 2017-06-30 11:15:04

我也有同样的问题,并从源代码中得到了答案

https://blueimp.github.io/jQuery-File-Upload/js/main.js中有一个maxFileSize: 999000

这是我的代码

代码语言:javascript
复制
$('#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,
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41076852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档