[Zope3-Users] save file to filesystem

k b mictlan.tecutli.0 at gmail.com
Wed Feb 27 17:33:25 EST 2008

i'm attempting to learn zope3, beginning with grok. i''ve managed to get
most of the functionality i need, but don't have a complete understanding of
the interworkings of the system. essentially i'm writing a small app that i
use to control mpd (music player deamon) by way of libmpdclient.py.

currently i'm held back by the inability to upload a file to the filesystem.
i understand that ZOBD.blob completes this funcionality. zope.conf is
configured for blobs, but i fail to understand how to save a blob to the
directory configured there. i've read this:
i've also looked the doc tests that come with z3c.blobfile. i've also found
information which states that zope.file (not zope.app.file) includes blob
funcionality. nonetheless, i've not been able to make it work. hopefully a
bit of code will help clarify the problem. the following works to save a
file to the zodb. i've tried many variations using blobfile and extfile
without success.

import grok
from zope import interface, schema
from megrok.form.fields import File

class IAudio(interface.Interface):
    name = schema.TextLine(title=u"Name")
    data = File(title=u"Audio file")

class Audio(grok.Model):

    def __init__(self, data, name):
      self.data = data
      self.name = name

class AddAudio(grok.AddForm):
    form_fields = grok.AutoFields(Audio)

    @grok.action('Add audio')
    def add(self, **data):
        obj = Audio(**data)
        self.context[name] = obj

this setup works to save a file to the zodb.
i've tried changing "from megrok.form.fields import File" to "from
z3c.blobfile import File". i've also tried having IAudio subclass IBlobFile,
to no avail.
in the archives of this list i've also found some references to z3c.extfile
and have tried subclassing it instead. can anyone give specific pointers on
how to modify the above code so that it stores files on the filesystem?

thanks for any and all help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20080227/406c031c/attachment.htm

More information about the Zope3-users mailing list