Tuesday, September 29, 2009

How to limit Plone's file upload size?

It would be nice if we could somehow limit the size of members' uploads. One step in this would be to limit the size for an individual file upload.

Follow-up: See /2009/09/folders-with-quotas.html for more along this track.

After digging in ATContentTypes' ATFile class, it turns out there's a validator for this, but it's disabled by default. It can be modified by tweaking the file etc/atcontenttypes.conf.in in the ATContentTypes product:

<archetype ATFile>
# maximum file size in byte, kb or mb
max_file_size 10mb

You can set it to just 1024 for 1024 bytes, or use kb's or mb's as above.

Next: how to change this value without touching ATContentTypes? There's a recipe called plone.recipe.atcontenttypes which sets ATContentTypes' configuration from the buildout. Just add this to your buildout:

parts =

recipe = plone.recipe.atcontenttypes
zope-instance-location = ${instance:location}
max-file-size = ATFile:10mb

1 comment:

davidjb said...

It's worth noting that ATBlob (Blob-based) content sizes are also tied directly to the configuration for ATFile as per this post. This is on account of them both using the same "checkFileMaxSize" AT validator. Helpful to know for Plone 4.x and above.