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

Registered by jhsware

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

Blueprint information

Status:
Complete
Approver:
Grok Doc
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
Steve Schmechel
Definition:
Approved
Series goal:
Proposed for 1.1
Implementation:
Implemented
Milestone target:
None
Started by
Steve Schmechel
Completed by
Steve Schmechel

Related branches

Sprints

Whiteboard

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.

UPDATE:
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:
<zodb>

  <blobstorage>

    # Standard Filestorage

    <filestorage>

      path ${data:path}

    </filestorage>

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

  </blobstorage>

Some other observations:

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

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

- 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.

Subscribers

No subscribers.