[Zope] Re: File Upload via form (with other form variable) and storing it in a database

Maik Jablonski maik.jablonski@uni-bielefeld.de
Mon, 03 Mar 2003 09:17:55 +0100

Edward Muller wrote:
> Okay... Saw that 
> But it doesn't tell me how to get the file into a postgres database
> though.

Take the content of the file and store it with an ExternalMethod
  in a BLOB-field... btw: I don't think that Postgres is a good storage 
for binary-objects...

# insertFile.py
# from 

import psycopg

def add_fileobject(self, obj_id, title, file, REQUEST=None):
     " insert binary file into postgres sql table "

     # open a database connection
     o = psycopg.connect("dbname=myDB user=postgres")

     # create cursor
     c = o.cursor()

     c.execute("INSERT INTO TBL_FILES (obj_id, imagetitle, imagedata) VALUES
(%(obj_id)i, %(img_title)s, %(data)s)",
                {'obj_id':obj_id, 'img_title':title,

     # commit on the database connection

     if REQUEST is not None:

Cheers, Maik
Deutsche/German Zope User Group (DZUG)