Storing a JPEG in MySQL-Database

Dave Benjamin dave at 3dex.com
Mon May 12 17:54:37 EDT 2003


"T. Kaufmann" <merman at snafu.de> wrote in message
news:3EBD3694.8040200 at snafu.de...
> I have to store some *.JPEGS in the MySQL-Database.
> How it's done?

You can use MySQL's BLOB type to contain the image data. You will need to
escape the data in your INSERT statement. The MySQLdb library comes with a
function called MySQLdb.escape_string() that will properly escape the
special characters that MySQL is sensitive to. If you have the Python
Cookbook, there's a good example on page 278. I haven't seen it online
anywhere.

Also consider storing the images on the filesystem, and just saving the
filename in the database.

Good luck,
Dave






More information about the Python-list mailing list