On 1/29/06, arthur debert <[EMAIL PROTECTED]> wrote:
> we want to set a max file size  (e.g. 400 kb) so we can keep our
> servers happy (those file will be processed by PIL). The idea is to
> avoid an uneducated user uploading his 10 mb digital camera files and
> giving the server a hard time.
>
> My question is, where would be the best place to check for the file
> size?
> [...]
> if I do it in _pre_save() will this only get called AFTER the file has
> been uploaded? if so, is there a way to check for this BEFORE the file
> is uploaded?

Sounds like a good candidate for a validator. Just write a validator
(see examples in django/core/validators.py) and add it to your
FileField's validator_list parameter. This will let you check the file
size before the file is uploaded.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Reply via email to