[Grok-dev] Re: [Zope3-Users] save file to filesystem

Martijn Faassen faassen at startifact.com
Wed Feb 27 18:19:59 EST 2008

Hi there,

I haven't had much experience with blobs yet (I hope to start working
with this in the near future).

>From my reading of the blobfile docs, I think the "File" object
defined in it is *not* a schema field, such as the
one you use from megrok.form. These things are different things
altogether, even though they're both called file.
blobfile tries to make its File object compatible with the file object
stored by the zope.app.file package. This is the
implementation of an object that *stores* the file data, not the field
that appears in the schema. From my cursory browsing
through z3c.blobfile it doesn't implement such a file field.

So, concept involved:

* the File field in a schema

* the actual object that ends up on your Python object, a File object
(altogether different, just same name). This stores your
  file in some way, by default in the ZODB, but now we want to use the
blob version.

* the widget that displays this field in a form.

I think unfortunately some custom work seems necessary to hook this
up. megrok.form uses collective.namedfile for its file upload widget.
Collective namedfile defines a field and widget for the file. Glancing
at it, I don't think it's much code, but we do need:

* a special 'BlobFile' field that stores the information in the ZODB

* probably a BlobNamedFile storage object that subclasses from the
existing blobfile File object, but adds a filename (which the named
file bits need)

* a new BlobNamedFileWidget widget  that subclasses NamedFileWidget
and creates a BlobNamedFile instead of a
  NamedFile. With a few tweaks to collective.namedfile we could make
this widget subclass really minimal, just introducing
  a file object factory in it or looking up some utility or adapter to
configure it, but even without that, it's going to be short.

I expect that all this is probably a bit intimidating for you to get
done yourself, but luckily there's help. I think this might make for a
good addition to megrok.form, which we're interested in expanding. I
think it makes sense for us to add blob file support in there along
the lines of what I sketched out above. Please join us in grok-dev and
we'll try to work it out with you. To start this off, I've cc-ed it
into that list as well as the developer of megrok.form.



More information about the Grok-dev mailing list