File Upload via form (with other form variable) and storing it in a database
How would I go about uploading a file via a form and store it in a postgres database using zope/zpt. I've never do this. I've used zope/zpt/zsql when dealing with forms before but never with a input type of "file". Any help or guidance would be appreciated. Thanks in advance -- Edward Muller Interlix - President Web Hosting - PC Service & Support Custom Programming - Network Service & Support Phone: 417-862-0573 Cell: 417-844-2435 Fax: 417-862-0572 http://www.interlix.com
Edward Muller wrote:
How would I go about uploading a file via a form and store it in a postgres database using zope/zpt.
I've never do this. I've used zope/zpt/zsql when dealing with forms before but never with a input type of "file".
There's an Example.zexp in the import-folder of Zope 2.6.x. Import it and have a look at the File-Library-Example. It's all there... -mj -- German Zope User Group (DZUG) - http://www.dzug.org/
Okay... Saw that But it doesn't tell me how to get the file into a postgres database though. On Fri, 2003-02-28 at 03:36, Maik Jablonski wrote:
Edward Muller wrote:
How would I go about uploading a file via a form and store it in a postgres database using zope/zpt.
I've never do this. I've used zope/zpt/zsql when dealing with forms before but never with a input type of "file".
There's an Example.zexp in the import-folder of Zope 2.6.x. Import it and have a look at the File-Library-Example. It's all there...
-mj -- Edward Muller
Interlix - President Web Hosting - PC Service & Support Custom Programming - Network Service & Support Phone: 417-862-0573 Cell: 417-844-2435 Fax: 417-862-0572 http://www.interlix.com
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 http://www.dzug.org/mailinglisten/zope/archive/2002/2002-11/1037545798840 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, 'data':psycopg.Binary(file.read())} ) # commit on the database connection o.commit() if REQUEST is not None: REQUEST.RESPONSE.redirect('index_html') Cheers, Maik -- Deutsche/German Zope User Group (DZUG) http://www.dzug.org/Members/mjablonski/
Maik Jablonski wrote:
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...
[snip] Why so? Do you have negative experience with BLOBs in Postgresql? I did some (very unscientific) tests with some mp3s once, and it seemed to perform quite well. This was with Postgresql 7.2, and about 500Mb of data. - peter.
participants (3)
-
Edward Muller -
Maik Jablonski -
Peter Sabaini