storing binary files to mySQL ???
user at domain.invalid
user at domain.invalid
Tue Dec 17 11:04:20 EST 2002
I solved this problem by converting the binary data into base64 using
the Python base64 module. If the MySQL default quote character is used
by base64, I replace that character with another one in the base64 data.
Since images tend to be big, I keep them in their own directory tree and
store only the names in the database.
I find setting up databases to be confusing. I have documented the
process in my newgroup program "fetchit" at
http://members.tripod.com/~edcjones/
fritz steindl wrote:
> On Mon, 16 Dec 2002 19:58:08 +0000, Fredrik Lundh wrote:
>
>
>>"steindl fritz" <python at floSoft.org> wrote:
>>
>>
>>>i try to store pictures in a blob field of mySQL
>>>
>>>
>>> file = open("c:\\picture.jpg", 'rb')
>>> picture = file.read()
>>>
>>> SQL ='INSERT INTO tbl_BLOB (attrName, attrValue) VALUES
>>>("nameOfPicture", ' + picture + ')'
>>>
>>> conn = CompatMysqldb.Connection("host", "username", "password",
>>> "db") curs = conn.cursor()
>>> curs.execute(SQL)
>>
>>what MySQL module are you using?
>>
>>("python CompatMysql" (without the quotes) is a googlewhack on
>>groups.google.com, and returns no hits at all on other parts of google.)
>>
>>anyway, in case this is Andy Dustman's version, and nothing else helps,
>>you can always import _mysql and use the escape_string function:
>>
>> import _mysql
>>
>> file = open("c:\\picture.jpg", 'rb')
>> picture = _mysql.escape_string(file.read())
>>
>>I'm pretty sure there's a better way, but I just un- installed MySQL on
>>this box, so I'll have to leave it to someone else to tell you what it
>>is.
>>
>></F>
>
>
>
> the mySQL module i use is CompatMysqldb.py
> sorry for losing the last 2 chars in my text
>
> thx for the rest of hints so far
>
> because i find only _mysql.pyd on the machine, which is not readable, i
> will search for any docs on the net, and come back hopefully with the
> solution or maybe more questions ...
>
>
> fritz
> (-:fs)
More information about the Python-list
mailing list