[Zope] Re: File Upload problems

Mark Evans mark.evans.b@bayer.com
Tue, 11 Mar 2003 15:44:50 -0800


Actually, Maik had it right, it just took me awhile to get it to work.  The key
was that the FileUpload object can be treated as a file object.  I was then able
to do this:

def main (image):
    dCon = dco.connect("foo/foo@myfoo")
    dCur = dCon.cursor()
    dCur.execute("insert into blobtest values ('2', EMPTY_BLOB())")
    dCur.execute("select * from blobtest where id='2' for update")
    r = dCur.fetchone()
    lob = r[1]
    lob.write(image.read())
    dCon.commit()
    return str(image.filename) +" was loaded"

This did what I wanted it to do.  What I was missing was the
lob.write(image.read()) syntax.  That took me awhile.
Thanks to Maik and Dieter for their help.

Mark



|---------+---------------------------->
|         |           Dieter Maurer    |
|         |           <dieter@handshake|
|         |           .de>             |
|         |                            |
|         |           03/11/2003 02:22 |
|         |           PM               |
|         |                            |
|---------+---------------------------->
  >---------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                           |
  |       To:       "Mark Evans" <mark.evans.b@bayer.com>                                                                     |
  |       cc:       zope@zope.org                                                                                             |
  |       Subject:  Re: [Zope] File Upload problems                                                                           |
  >---------------------------------------------------------------------------------------------------------------------------|




Mark Evans wrote at 2003-3-10 11:51 -0800:
 > ....
 > I am trying to upload an image file from a form to an External Method ....
 > ....
 > The external method is called from a DTML method called "execute_loadblob"
 which
 > contains the call:
 >
 > <dtml-var expr="writeBlob(image)">
 >
 > The external method is:
 >
 > import sys,os,string,DCOracle2 as dco
 > def main(image):
 >      ...
 >      do something here with image, doesn't matter what
 >      ...
 >       return "Something was done"
 >
 > =============================================================
 >
 > The gist of the error received, is that image is a "
 > ZPublisher.HTTPRequest.FileUpload instance at 1046b04"
 > instead of being something I can acutally manipulate.  Why is this and how do
 I
 > access either the file or the URL pointing to the file?

This error message does not seem to fit to your description.

Instead, it looks as if the uploaded image were returned as
result of the web request. This should never happen (Web request
results should be elementary data types). When
ZPublisher is confronted with an (non-elementary) object as response to
a request it raises an error.


Dieter