[Zope] Can Zope extract an image (BLOB) from an RDB ?

chas panda@skinnyhippo.com
Thu, 23 Mar 2000 07:18:56 +0800


Yikes, just noticed this one sat in my outbox unqueued :

Going back a month, just have to say thank you Chris.

It does work - I was getting the earlier error messages due
to being a bit ambitious and trying to display all of the 
images.

Just for the record, to get it to work :

1. Create a ZSQL method <ZSQL_SelectPicture> to extract the binary data 
   field ('picture') of one (1) image. That's the important part - one 
   single image.  Don't try to select several records for further logic
   processing.

2. Create a DTML method that returns nothing more than the 
   BLOB data from the ZSQL method, with the correct content type.
   Eg. 
  <dtml-call "RESPONSE.setHeader('content-type', 'image/jpeg')"><dtml-in
ZSQL_SelectPicture><dtml-var picture></dtml-in>

Accessing the DTML method directly will return the image.

chas

>I've never done it, and it's not well-documented (ie. I have no idea if
>it really works), but I believe the Oracle DA can retrieve BLOBS... Here
>the CHANGES.txt file from ZOracleDA:  
>
>Z Oracle DA Releases
>
>  2.2.0
>
>    Added a small feature that allows you to access LOBs in the Oracle 
>    database.  To do this, you must have your maximum number of
>    results set to '1'.  Otherwise, it won't work.
>
>    In addition, several bugs were resolved.
>
>  2.1.0 
>
>    Based on DCOracle new release that fixes many outstanding bugs.
>    In addition, it is now integrated with the Zope2 transaction
>    system.
>
>  2.0.0
>
>    This is the first version of the database adapter using DCOracle
>    for Zope.  This database adapter is based on an earlier database
>    adapter for Principia, which is why this is revision 2.
>
>
>
>chas wrote:
>> 
>> I've got 8000 photos (jpeg format) stored in an Oracle
>> database. The table that contains the photos has these
>> columns which are of interest :
>> 
>>  PICTURE                                  LONG RAW
>>  PICTURE_LENGTH                  NOT NULL NUMBER(14)
>> 
>> My goals in order of progression are :
>> 
>> 1. Extract the image from the database using ZSQL methods
>> 
>> 2. Serve that image up directly to the web browser
>> 
>> 3. Save the image to the filesystem or, even better,
>>    create a Zope Image Object
>> 
>> Unfortunately, I'm stuck at step 1. Doing a request on
>> the database with ZSQL methods is returning :
>> 
>> Error, oci.error: (911, 'ORA-00911: invalid character\012')
>> 
>> Is there any way for Zope to handle this or is this going
>> to involve python-DCOracle scripts instead and then uploading
>> into Zope ?
>> 
>> Thank you very much in advance,
>> 
>> chas
>> 
>> _______________________________________________
>> Zope maillist  -  Zope@zope.org
>> http://lists.zope.org/mailman/listinfo/zope
>> **   No cross posts or HTML encoding!  **
>> (Related lists -
>>  http://lists.zope.org/mailman/listinfo/zope-announce
>>  http://lists.zope.org/mailman/listinfo/zope-dev )
>
>-- 
>Chris McDonough
>Digital Creations, Inc.
>Zope - http://www.zope.org
>