[Zope] Upload files in Zope and store elsewhere

Tres Seaver tseaver@palladion.com
Wed, 22 Mar 2000 09:54:56 -0600


Chris Withers <chrisw@nipltd.com> writes:
> 
> I'd also love to be able to store files uploaded through a Zope form into a
> MySQL database so if
> anyone else has done this successfully, particularly for medium size files
> (5-6 MB) please can you
> let the list know!
> 
> cheers,
> 
> Chris
> 
> Marius Kjeldahl wrote:
> >
> > After some helpful advice, I have been successful in uploading files
> > (images) to Zope. Now I am trying to stuff the uploaded images in a
> > MySQL database, but am not able to access the image data.
> >
> > If I try to stuff the image data "raw" into the database by declaring a
> > image:string parameter to the ZSQL Method and  <dtml-sqlvar image> in
> > the ZSQL code I get a string like "<ZPublisher.HTTPRequest.FileUpload
> > instance at 87956214>".
> >
> > Another approach I have tried was <dtml-var image fmt=sql-quote>, but
> > this complains about the image being an instance and not a string.
> >
> > Another approach has been to access the actual "raw" image data using
> > image.data in various combinations, but I have not gotten this to work
> > anywhere (contrary to what it seems other people have managed to do),
> > see this
> >
> > http://www.egroups.com/group/zope/26227.html?
> >
> > posting.
> >
> > Looking through Image.py I see quote a few methods for accessing the
> > image as a "web" object through the use of URL. Internally, Image.py
> > uses the data attribute extensively, but I have not been able to access
> > this from within DTML (and I guess this has to do with data not being
> > listed in either the properties or permission sections of Image.py).
> >
> > My final try will probably be to resort to using an External method to
> > get access to the "full" Image.py object (including data), but I was
> > hoping to avoid this.
> >
> > Has anybody done this (uploading in Zope and storing the data outside of
> > Zope) successfully? If so, please give me a hint..

My advice here is not based on work with Zope, but on years of painful RDBMS
experience:  I do *not* recommend storing large BLOBs in any existing RDBMS --
they aren't built for them, and generally make your life miserable when you
try.  Most of the reasons you would choose to use an RDBMS (performance,
replication, stability, searchability, etc.) don't apply when it comes to large
BLOBs;  you are still much better off storing the "BLOB" in a filesystem
somewhere, and then storing a path/URL to it in the RDBMS.

With Zope, BLOBs present another issue:  because they aren't standardized, each
RDBMS has a proprietary API for BLOBS;  the Zope database adapter therefore has
to have custom code for each RDBMS, making the BLOB code one of the likeliest
sources of weird, hard-to-reproduce bugs I can think of.

In short, *don't go there*.  Really, I'm serious.

Tres.

P.S.  If you *have* to go there, use the Python base64 module to encode
      binary data.
-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com