[PyGreSQL] Storing images/documents in bytea fields as base64 encoded strings
Sean Davis
sdavis2 at mail.nih.gov
Sat Dec 30 14:29:25 EST 2006
G. Skerrett wrote:
> We have are developing an internal application to store documents and
> images in the postgresql db.
> After struggling with escaping the low order characters for
> including in the bytea field, we hit upon the idea of simply using the
> python base64 modules to encode files as base64 strings and store the
> string in the database.
>
> We think that the benefit is doing this is;
> 1) using an industry standard encoding mechanism so they could be
> decoded with another application if desired.
> 2) the images/documents are "web/email ready", so storing and encoding
> stage will encur a penalty hit, hwoever, the retreival will not.
>
> If any one on this list has suggestions/comments or can see a problem
> with this strategy, we would appreciate comment.
I think this is a pretty common approach. You can also store
base64-encoded in a simple TEXT field. If you want the DB to do the
work, look here:
http://www.postgresql.org/docs/current/static/functions-string.html
Sean
More information about the PyGreSQL
mailing list