我对plupload队列有疑问
我想知道在哪里可以放置最大文件上传,所以我只想让用户上传总共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++;
});
}
});
});
答案 0 :(得分:2)
查看文档中的queue process。
像'loaded'这样的方法可用于计算上传的总数,然后从用户上传到的目录大小的总和中减去。 (Directory_size - uploaded_size = total_available)
然后,如果total_available是负值,那么您就知道要拒绝它。