storing binary data in an external database
I need to be able to store images and the like in a postgres table. It would seem that <dtml-sqlvar> isn't going to be what I want because there isn't a type definition for what I want (the data isn't exactly a string, right?). I'm reading in the file contents using REQUEST['file'].read(), which works great for ascii text files, but not binaries. Any help appreciated. -- Bryan C. Andregg Duke University Medical Center Programmer Dept. of Anesthesiology e <bryan.andregg@duke.edu> p +1 919 684 6201
Howdi. On Wed, Mar 06, 2002 at 04:31:42PM -0500, Bryan C. Andregg wrote:
I need to be able to store images and the like in a postgres table. It would seem that <dtml-sqlvar> isn't going to be what I want because there isn't a type definition for what I want (the data isn't exactly a string, right?).
I'm reading in the file contents using REQUEST['file'].read(), which works great for ascii text files, but not binaries.
Well REQUEST['file'].read() is ok for binaries, just passing it 1to1 through the database method and adapter may be a bit messy (mixing up sql code aso) so i prefer to encode (e.g. base64) the binary data so it gets "string-compatible" and you can safely insert it into your sql method.
Any help appreciated. -- Bryan C. Andregg Duke University Medical Center Programmer Dept. of Anesthesiology e <bryan.andregg@duke.edu> p +1 919 684 6201
Greetings Christian -- Christian Theune - ct@gocept.com gocept gmbh & co.kg - schalaunische strasse 6 - 06366 koethen/anhalt tel.+49 3496 3099112 - fax.+49 3496 3099118 mob. - 0178 48 33 981 reduce(lambda x,y:x+y,[chr(ord(x)^42) for x in 'zS^BED\nX_FOY\x0b'])
On Wed, Mar 06, 2002 at 09:42:10PM +0100, Christian Theune mailed:
Well REQUEST['file'].read() is ok for binaries, just passing it 1to1 through the database method and adapter may be a bit messy (mixing up sql code aso) so i prefer to encode (e.g. base64) the binary data so it gets "string-compatible" and you can safely insert it into your sql method.
base64 encoding is exactly what I want, thanks for the reminder. Cheers, -- Bryan C. Andregg Duke University Medical Center Programmer Dept. of Anesthesiology e <bryan.andregg@duke.edu> p +1 919 684 6201
I believe there's a Blob (I think it's called) binary data type for sql - there was a thread a while ago in this list, someone storing large images in sql using those. personally, I'd use ZODB, or just the file system (LocalFS or ExtImage)
From: "Bryan C. Andregg" <bryan.andregg@duke.edu> Date: Wed, 6 Mar 2002 16:31:42 -0500 To: zope@zope.org Subject: [Zope] storing binary data in an external database
I need to be able to store images and the like in a postgres table. It would seem that <dtml-sqlvar> isn't going to be what I want because there isn't a type definition for what I want (the data isn't exactly a string, right?).
I'm reading in the file contents using REQUEST['file'].read(), which works great for ascii text files, but not binaries.
Any help appreciated. -- Bryan C. Andregg Duke University Medical Center Programmer Dept. of Anesthesiology e <bryan.andregg@duke.edu> p +1 919 684 6201
participants (3)
-
Bryan C. Andregg -
Christian Theune -
marc lindahl