[Zope-DB] Help - upload images to Postgresql

CY CY" <cyhoong@pc.jaring.my
Tue, 8 Apr 2003 15:48:36 +0800


Yves

Thank you for your advice and appreciate your help very much.

I hope if you can help me to understand more on "<dtml-var
quoted_pic>::bytea

I had tried using:
i)  <dtml-var quoted_pic>::bytea
ii) <dtml-var pic sql_quote>::bytea
iii) <dtml-var pic html_quote>::bytea

Can you advise me where I went wrong?

i) error message using <dtml-var quoted_pic>::bytea:
====================================
Error Type: KeyError
Error Value: quoted_pic

ii) error message using <dtml-var pic sql_quote>::bytea:
======================================
Error Type: IntegrityError
Error Value: ERROR: parser: parse error at or near "<" insert into photo(
person_id, comments, pic) values ('123', 'aaa', ::bytea )

ii) error message using <dtml-var pic html_quote>::bytea:
======================================
Error Type: IntegrityError
Error Value: ERROR: parser: parse error at or near ";" insert into photo(
person_id, comments, pic) values ('123', 'aaa',
<ZPublisher.HTTPRequest.FileUpload instance at 0x8ae867c>::bytea )


Photo Table Creation
===============
create table photo
(
  person_id   char(16) not null,                - for simplicity
  comments  char(20),
  pic       bytea

);

uploadPhoto_sql
============
insert into photo(
  person_id, comments, pic)
values
  (<dtml-sqlvar person_id type="string">,
   <dtml-sqlvar comments type="string">,
   <dtml-var pic html_quote>::bytea
   )

uploadPhoto_form
=============
<form action="uploadPhoto_action" method="post"
enctype="multipart/form-data">
<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/*" html_quote>
  </tr>
  <tr><td>&nbsp;&nbsp;</td></tr>
  <tr><td align="right"><input type="reset" name="submit"
value="Reset"></td>
        <td><input type="submit" name="submit" value="Upload"></td>
  </tr>

uploadPhoto_Action
===============
 <dtml-call "uploadPhoto_sql
       (person_id=REQUEST.get('person_id'),
        comments=REQUEST.get('comments'),
        pic=REQUEST.get('pic') )">

 <dtml-call "RESPONSE.redirect('uploadPhoto_form')">