Hello Zopist I need some help in uploading .gif & jpeg files to Postgresql. My current server is running Zope2.5.1 on RH8.0 with Postgresql7.2.2. I have create a simple form to capture some digital images for uploading to Zope server from my PC (WIn98). However I encounter an error message (below). The system is looking for the images in Zope server while the actual image for uploading resides in the PC. How I do "tell" the Zope the location of the image file? TQ in advance Error message: ========== Z SQL Method at /STARS/Photo/uploadPhoto_sql Help! ---------------------------------------------------------------------------- ---- Error, psycopg.IntegrityError: ERROR: lo_import: can't open unix file "g:imagesirds.gif": No such file or directory insert into photo( person_id, comments, pic) values ('robert', 'happy bird day', lo_import ('g:\images\birds.gif') ) ---------------------------------------------------------------------------- ---- SQL used: insert into photo( person_id, comments, pic) values ('robert', 'happy bird day', lo_import ('g:\images\birds.gif') ) Photo upload Form ================== <dtml-var standard_html_header><h2><dtml-var title_or_id></h2> <form action="uploadPhoto_action" method="post"><table> <tr> <td>Person ID:</td> <td><input type="text" name="person_id" maxlength="16" size="20"></td> </tr> <tr> <td>Comments:</td> <td><input type="text" name="comments" maxlength="20" size="20"></td> </tr> <tr> <td>Filename: </td> <td><input type="file" name="pic" accept="image/*"> </tr> <tr><td> </td></tr> <tr> <td align="right"><input type="reset" name="submit" value="Reset"></td> <td><input type="submit" name="submit" value="Upload"></td> </tr> <dtml-var standard_html_footer> uploadPhoto_action Method ==================== <dtml-var standard_html_header><h2><dtml-var title_or_id> <dtml-var document_title></h2> <dtml-call "uploadPhoto_sql (cust_id=REQUEST.get('person_id'), comments=REQUEST.get('comments'), pic=REQUEST.get('pic') )"> <dtml-call "RESPONSE.redirect('uploadPhoto_form')"> <dtml-var standard_html_footer>
CY wrote:
I need some help in uploading .gif & jpeg files to Postgresql. ... The system is looking for the images in Zope server while the actual image for uploading resides in the PC. How I do "tell" the Zope the location of the image file?
Zope ships with an Example.zexp wich includes a FileLibrary. Please have a look at it how to handle File-Uploads. -mj
The system is looking for the images in Zope server while the actual image for uploading resides in the PC. How I do "tell" the Zope the location of the image file?
I can't tell you how to stick a BLOB into Postgres syntax-wise. What I can tell you is this: inserting a file path isn't going to work. The server has no way dealing with that. When you submit a form with an input with type 'file' that file is sucked off the client's machine and sent to Zope, which makes it into a Python file-appearing object. You can operate on this the same way as any Python file object. To put that data into the database, you must put it into an SQL query, and that means dtml-sqlvar statements. When you use sqlvar on a fileish object, my guess is that is simply inserts the contents (though I haven't checked.) So you can probably just do it like any regular BLOB insertion, but sticking a dtml-sqlvar tag where the binary data should be. It probably works much like a regular zsql insert. At worst, you write a small script to return the fileish object's data and use a regular dtml-var on that. --jcc
participants (3)
-
CY -
J Cameron Cooper -
Maik Jablonski