-1

我对 plupload 队列有疑问

我想知道我可以将最大文件上传放在哪里,所以我只希望用户上传文件的 mixmum 为 1gb,因此例如 10 个 100mb 的文件总共为 1gb,之后用户不能上传任何文件

$(document).ready(function () {

    $(function () {
        $("#uploader").pluploadQueue({
            runtimes: 'html5, html4',
            url: '/Upload/Upload',
            max_file_size: '1gb',
            unique_names: true,
            multipart: true,
            multiple_queues: false,
            filters: [
                { title: "Bestanden", extensions: "jpg,gif,png,docx,wmv,xslx,avi" },
            ],

            preinit: {
                FileUploaded: function (up, file, response) {
                    var data = response.response; //$.parseJSON(response.response);

                    $('<input>').attr({
                        type: 'hidden',
                        name: 'fileId' + data,
                        value: data
                    }).appendTo('#uploadFinishedForm');

                    if (data.error == 1) {
                        uploader.trigger("Error", { message: "'" + data.message + "'", file: file });
                        console.log('[Error] ' + file.id + ' : ' + data.message);
                        return false;
                    }
                },

                UploadComplete: function (up, files) {
                    window.setTimeout(function (form) {
                 //       $('#uploadFinishedForm').submit();
                        $('.nextButton').append('<input type="submit" class="btn btn-large btn-success submit-btn" value="Transfer" />');
                    }, 2000)

                },

                Init: function (up, info) {
                    $('#uploader_container').removeAttr("title");
                }
            }
        });


        $('#uploadForm').submit(function (e) {
            var uploader = $('#uploader').pluploadQueue();
            if (uploader.files.length > 0) {
                uploader.bind('StateChanged', function () {
                    if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                        $('#uploadForm').submit();
                    }
                });

                uploader.start();
            } else {
                $('#uploadInfo').html('Zonder foto\'s valt er niets te uploaden!');
            }

            return false;



        });

        $(".btnDel")
                .live("click", function () {
                    if ($("tr.person-input-row").length > 1) {
                        if (confirm("Wilt u deze naam wilt verwijderen?")) {
                            $(this).parents("tr.person-input-row").fadeOut("normal", function () { $(this).remove(); refineIndexes(); });
                        }
                    } else {
                        alert("Naam kan niet worden verwijderd.\n\nEr dient minimaal 1 email adres opgegeven te worden.");
                    }
                    return false;
                });

        $("#btnAdd")
                .live("click", function () {
                    // duplicate a row and force unique element id's
                    var table = $("#participants_list");
                    var tr = table.find('tr:first').next().clone()
                    $(tr).find('input').each(function () {
                        if (this.type === "text") { $(this).val(''); } // clear text
                    });
                    $(tr).appendTo(table);

                    refineIndexes();
                });

        function refineIndexes() {
            // function to duplicate a row and update unique element id's
            var index = 0;
            $("#participants_list").find('tr').next().each(function () {
                $(this).find('input').each(function () {

                    var newId = this.id.replace(parseInt(this.id.match(/[\d\.]+/g)[0], null).toString(), index);
                    var newName = this.name.replace(parseInt(this.name.match(/[\d\.]+/g)[0], null).toString(), index);

                    // IE7 struggling with 'name' attribute
                    if ($.browser.msie && $.browser.version.substr(0, 1) <= 7) {
                        // for readability
                        var oldInput = $(this);

                        // recreate new input and add to DOM
                        var newInput = $("<input type=\"" + this.type + "\" id=\"" + newId + "\" name=\"" + newName + "\" />").addClass(oldInput.attr("class")).val(oldInput.val()).insertAfter(oldInput);

                        // set checked attribute on radio
                        // remove old input from DOM
                        oldInput.remove();

                    } else {
                        $(this).attr({ id: newId, name: newName });
                    }
                });

                $(this).find('.num').text(function () {
                    var elSpan = $(this).text();
                    var nr = parseInt(elSpan.match(/[\d\.]+/g)[0], null);
                    return elSpan.replace(nr.toString(), index + 1);
                });

                $(this).find('label').attr('for', function () {
                    elFor = $(this).attr('for');
                    var nr = parseInt(elFor.match(/[\d\.]+/g)[0], null);
                    return elFor.replace(nr.toString(), index);
                });
                index++;
            });


        }



    });
});
4

1 回答 1

2

查看文档中的队列过程

'loaded' 等方法可用于计算上传的总数,然后从用户上传到的目录大小的总数中减去。(Directory_size - upload_size = total_available)

那么如果total_available 是一个负值,那么你就知道拒绝它。

于 2013-05-28T15:21:04.807 回答