Go to Google Groups Home    Django users
Re: Limiting file size before upload?

Malcolm Tredinnick <malc...@pointy-stick.com>

On Mon, 2006-07-10 at 10:42 +0000, daniel.tie...@gmail.com wrote:
> Hi.

> Is there a way to limit upload file size *before* the upload is
> accepted?

> Say I want to give people the option of uploading movie files, but I
> want to limit them to 4MB per movie. If I understand the upload
> behaviour of Django correctly, the file is first accepted into main
> memory (*) , after which I have access to metadata.
> This would mean that somebody could easily OOM my Apache just by
> uploading a huuuuuge file. Also, in a hosted environment, this is
> unnecessary traffic which I'd have to pay for.

Without answering your question directly, let me just point out that
even if such a limit existed in Django, it still wouldn't help your
Apache process, since it is already accepting the data.

Fortunately, you *can* control this at the Apache level. Look at the
LimitRequestBody directive.

Regards,
Malcolm