Created
April 16, 2011 02:42
-
-
Save Alir3z4/922807 to your computer and use it in GitHub Desktop.
using plupload and with django to limit files uploading with some effect!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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