hello, <br>i&#39;m attempting to learn zope3, beginning with grok. i&#39;&#39;ve managed to get most of the functionality i need, but don&#39;t have a complete understanding of the interworkings of the system. essentially i&#39;m writing a small app that i use to control mpd (music player deamon) by way of libmpdclient.py. <br>
<br>currently i&#39;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&#39;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&#39;ve also looked the doc tests that come with z3c.blobfile. i&#39;ve also found information which states that zope.file (not zope.app.file) includes blob funcionality. nonetheless, i&#39;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&#39;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>&nbsp;&nbsp;&nbsp; name = schema.TextLine(title=u&quot;Name&quot;)<br>&nbsp;&nbsp;&nbsp; data = File(title=u&quot;Audio file&quot;)<br>
<br><br>class Audio(grok.Model):<br>&nbsp;&nbsp;&nbsp; interface.implements(IAudio)<br><br>&nbsp;&nbsp;&nbsp; def __init__(self, data, name):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.data = data<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://self.name">self.name</a> = name<br><br>class AddAudio(grok.AddForm):<br>
&nbsp;&nbsp;&nbsp; grok.context(uploadtest)<br>&nbsp;&nbsp;&nbsp; form_fields = grok.AutoFields(Audio)<br><br>&nbsp;&nbsp;&nbsp; @grok.action(&#39;Add audio&#39;)<br>&nbsp;&nbsp;&nbsp; def add(self, **data):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj = Audio(**data)<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; self.context[name] = obj<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.redirect(self.url(self.context))<br>
<br><br>this setup works to save a file to the zodb. <br>i&#39;ve tried changing &quot;from megrok.form.fields import File&quot; to &quot;from z3c.blobfile import File&quot;. i&#39;ve also tried having IAudio subclass IBlobFile, to no avail. <br>
in the archives of this list i&#39;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>