...Never mind the why. The photo data (small - 80kb JPEGs) has to go into the PostgresSQL database. I'm using something like this: SQL_add_photo: insert into photo (id,data) values ( <dtml-sqlvar id type=int>, <dtml-sqlvar data type=string>) add_photo: container.SQL_add_photo(id,file.read()) index_html: <form action="add_photo" method="post" enctype="multipart/form-data"> <input type="text" name="id"> <input type="file" name="file"> <input type="submit" name="Add"> </form> But I get: Error Type: Programming Error Error Value: ERROR: Unterminated quoted string insert into photo (id,data) values ( 17, '<y-umlaut><a accent> Any ideas? Apart from base64 encoding, that is... Regards, Phil +----------------------------------+ | Phil Mayers, Network Support | | Centre for Computing Services | | Imperial College | +----------------------------------+
On 22 Jun 2001 12:46:30 +0100, Mayers, Philip J wrote:
...Never mind the why. The photo data (small - 80kb JPEGs) has to go into the PostgresSQL database. I'm using something like this:
SQL_add_photo:
insert into photo (id,data) values ( <dtml-sqlvar id type=int>, <dtml-sqlvar data type=string>)
add_photo:
container.SQL_add_photo(id,file.read())
you're sending binary data (file.read()) but tell zope to insert it as a string. i don't even know if zope supports a type=binary switch. the best thing you can do is to is to write a python method that directly uses psycopg and its Binary() constructor. mmm... psycopg does not have a Binary yet... ok, in a python metod try out the following code (we define a Binary class, as per DBAPI-2.0, that way you'll easily use psycopg Binary when implemented, in a few days i hope): import psycopg class Binary: def __init__(self, s): self.s = s def __str__(self): return "'" + join(map(lambda x: '\\%o' % ord(x), self.s), '') + "'" def add_photo(id, file): dict = {'id': int(id), 'data':Binary(file.read())} o = psycopg.connect("your connection string here") c = o.cursor() c.execute("INSERT INTO photo (id, data) VALUES (%(id)d, %(data)s)", dict) c.commit() hope this helps, federico -- Federico Di Gregorio MIXAD LIVE Chief of Research & Technology fog@mixadlive.com Debian GNU/Linux Developer & Italian Press Contact fog@debian.org All programmers are optimists. -- Frederick P. Brooks, Jr.
...Never mind the why. The photo data (small - 80kb JPEGs) has to go into the PostgresSQL database. I'm using something like this:
OK, I dont ask *why*, but I decided I put only metadata about photos, PDF's and other binary stuff in my database, and the binary stuff itself in the ZODB. Thats a lot less headaches for me... (in my opinion, a RDBMS is usefull for combining large tables of small rows. binary large objects are not really usefull to put in there. Of course I do not now the requirements of your project and you asked not to ask :-) Reinoud
participants (3)
-
Federico Di Gregorio -
Mayers, Philip J -
Reinoud van Leeuwen