Skip to content

Instantly share code, notes, and snippets.

@gileno
Created September 26, 2011 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gileno/1242148 to your computer and use it in GitHub Desktop.
Save gileno/1242148 to your computer and use it in GitHub Desktop.
File Size verification
from django.template.defaultfilters import filesizeformat
def clean_file(self):
if self.cleaned_data['file']:
size = self.cleaned_data['file'].size
max_size = settings.MAX_GROUP_FILE_SIZE
if size > max_size:
raise forms.ValidationError(_(u'O tamanho máximo do arquivo deve ser de %s') % filesizeformat(max_size))
return self.cleaned_data['file']
@fandrefh
Copy link

Desculpe a minha ignorância, e vejo também que já faz tempo que foi postado o código, mas preciso que me diga como utilizo esta função, como faço pra ela validar e verificar realmente o tamanho do arquivo que se está sendo upado atende ao limite?

No aguardo, abraços.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment