Skip to content

Instantly share code, notes, and snippets.

@Alir3z4
Created April 16, 2011 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Alir3z4/922807 to your computer and use it in GitHub Desktop.
Save Alir3z4/922807 to your computer and use it in GitHub Desktop.
using plupload and with django to limit files uploading with some effect!
var maxfiles = {{ maxfiles }}; // {{ maxfiles }} returns from views.py
$(function() {
$("#uploader").pluploadQueue({
runtimes : 'gears', // Initialize gears runtime
url : '{{ obj.get_image_upload_url }}', // Url to current object image uploading url
max_file_size : '4mb',
chunk_size: '4mb',
multiple_queues : true,
multi_selection: false, // It's necessary for file uploading limit
rename: true,
drop_element: 'uploader',
sortable: true,
filters: [
{title : "Image files", extensions : "jpg,gif,png"}
],
headers : {'X-Requested-With' : 'XMLHttpRequest', 'X-CSRFToken' : '{{csrf_token}}'}, // Initialize CSRFToken headers for django-csrf_token
init : {
FilesAdded: function(up, files) { // Fire up after file added to uploader
plupload.each(files, function(file) {
if (up.files.length > maxfiles) { // If count of files greater than 'maxfiles' then remove it
up.removeFile(file);
}
});
if (up.files.length >= maxfiles) { // If count of files greater than 'maxfiles' then hide add-files button
$('#uploader_browse').hide("slow");
}
},
FilesRemoved: function(up, files) {
if (up.files.length < maxfiles) {
$('#uploader_browse').fadeIn("slow");
}
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment