hello, <br>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. <br>
<br>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: <a href="http://tarekziade.wordpress.com/2007/09/14/to-blob-or-not-to-blob/">http://tarekziade.wordpress.com/2007/09/14/to-blob-or-not-to-blob/</a><br>
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. <br>
<br>import grok<br>from zope import interface, schema<br>from megrok.form.fields import File<br><br>class IAudio(interface.Interface):<br> name = schema.TextLine(title=u"Name")<br> data = File(title=u"Audio file")<br>
<br><br>class Audio(grok.Model):<br> interface.implements(IAudio)<br><br> def __init__(self, data, name):<br> self.data = data<br> <a href="http://self.name">self.name</a> = name<br><br>class AddAudio(grok.AddForm):<br>
grok.context(uploadtest)<br> form_fields = grok.AutoFields(Audio)<br><br> @grok.action('Add audio')<br> def add(self, **data):<br> obj = Audio(**data)<br> self.context[name] = obj<br> self.redirect(self.url(self.context))<br>
<br><br>this setup works to save a file to the zodb. <br>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. <br>
in the archives of this list i've also found some references to z3c.extfile<br>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? <br>
<br>thanks for any and all help, <br>kevin<br>