Handling file uploads with zope.app.file and zope.file

Registered by jhsware on 2009-06-17

If you want to handle files in zope, you can use the zope.app.file and zope.file packages.

Blueprint information

Grok Doc
Needs approval
Steve Schmechel
Series goal:
Proposed for 1.1
Milestone target:
Started by
Steve Schmechel on 2010-03-15
Completed by
Steve Schmechel on 2010-03-15

Related branches



2010-03-14 Steve Schmechel

Added some working example code to the how to so that users can run the code in an application and see it work.

The blobstorage stuff seems to work now from the latest grokproject svn trunk.

However, the procedure is still confusing because it creates the FileContainer container floating by itself without any clear reference of how to make it work in an actual grokproject application. All howto's should really start from a common point of having just run a new grokproject and show how to modify the initial app.py file to incorporate the information in the howto.

When trying to use the code as the top level container the add form works but you can not view the files without getting a "The page that you are trying to access is not available" error. It appears that the FileContainer should exist below the top level container but how to link it in is never shown.


Needs some clean-up. Especially, regarding the use of zope.file

etc/zope.conf.in needs to be modified so that you don't get:
  Unsupported: Storing Blobs in <ZODB.FileStorage.FileStorage.FileStorage object at 0x457cc90> is not supported.

The <zodb> section should be changed as follows:


    # Standard Filestorage


      path ${data:path}


  blob-dir ${buildout:directory}/parts/data/blobs


Some other observations:

- Nothing about how to traverse to a file list or upload form.

- Maybe include a basic template for listing files:
      <h1>File List</h1>
        <li tal:repeat="key python:context.keys()">
            <a tal:attributes="href python:view.url(context[key])" tal:content="python:key">File Name</a>
      <a href="upload">Upload a new file</a>

- The how-to should start from a grokproject-based project rather than a floating class definition.

- Either make the FileContainer class the grok.application or demonstrate how to add it to a parent container including the required "Super" statement.
    def __init__(self):
        super(ParentContainer, self).__init__()
        self['files'] = FileContainer()

- Explain where the name chooser should be defined in relation to the other code.
  - It appears that the name chooser wants a return value when it is in the same module as the upload class.
  - When the context is an add method in FileContainer's parent container the chooser needs a third parameter.
  (I don't understand adapter registration enough to explain this, but it has tripped me up before.)


Work Items

This blueprint contains Public information 
Everyone can see this information.


No subscribers.