Attention

This document was written for an old version of Plone, Plone 2.5.x, and was last updated 898 days ago.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Storing files on the file system using FileSystemStorage

by Mike Takahashi last modified Dec 06, 2009 09:27 PM
You have a Plone site, but you deal with large files such as documents that are +100MB or hundreds of images and you don’t want to store them in the ZODB.

Populating your ZODB with large files can inflate it into a huge size in no time.  The ZODB also keeps track of each change to a file, which revisions the whole object. Repacking your Data.fs file or even performing regular backups once your ZODB gets too large can be a cumbersome task as well.

Luckily, there is an excellent product called FileSystemStorage that allows you to store files added to your Plone site onto your file system.  FileSystemStorage works transparently in the background and allows users in Plone to add and manage content stored on the file system no differently than the standard Plone way. All it takes is a few lines of additional code added to a custom content type to store files on the file system and you are off and running.

Once you have installed and configured FileSystemStorage (the README.txt that comes with FileSystemStorage is very well documented) you will need to create, or modify your custom content type. When this new content type is then added in Plone, it knows to store the content on the file system and not in the ZODB.

In this example, I created a new custom content type called MyFile (via ArchGenXML), which was derived from ATFile.

The following lines (courtesy of Andreas Jung) were then added to my python file MyFile.py.

def updateSchema(schema):

    field = schema['file']
    field.storage = FileSystemStorage()
    field.registerLayer('storage',field.storage)

class MyFile(ATFile):
    .....    
    .....
    schema = MyFile_schema
    updateSchema(schema)
    .....

 

Once you add the code, restart Zope and then install or reinstall your custom content type. Now when content is added via your custom content type, it will be stored on the file system instead of the ZODB.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.