hello,
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:
http://tarekziade.wordpress.com/2007/09/14/to-blob-or-not-to-blob/
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):
    interface.implements(IAudio)

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

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

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


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,
kevin
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to