storing binary files to mySQL

steindl fritz python at floSoft.org
Thu Dec 19 19:15:24 EST 2002


Hrissimir Neikov wrote:

>> 
>> but unfortunately this worked only for text files (read binary) and not
>> for real binaries
>> 
>> ----------------
>> 
>> binaries still crashed at 'INSERT TO' with an mysql error
>> 
> 
> There is a standard module base64. Try using it.



i found this docu - sounds easy -

===============================================================
base64 index
/usr/lib/python2.2/base64.py

Conversions to/from base64 transport encoding as per RFC-1521.
 
Modules
           
binascii
 
Functions
             

decode(input, output)
Decode a file.

decodestring(s)
Decode a string.

encode(input, output)
Encode a file.

encodestring(s)
Encode a string.

test()
Small test program

test1()
 
Data
              MAXBINSIZE = 57
MAXLINESIZE = 76
__all__ = ['encode', 'decode', 'encodestring', 'decodestring']
__file__ = '/usr/lib/python2.2/base64.pyc'
__name__ = 'base64'
================================================================

BUT NOT FOR ME

-------------------------------------------------------
import base64

file = open("c:\\picture.jpg", 'rb')
image = file.read()
codedImage = None
base64.encode(image, codedImage)


Traceback (most recent call last):
  File "C:\Python21\o2db\testmysl.py", line 6, in ?
    base64.encode(file.read(), codedImage)
  File "C:\PYTHON21\lib\base64.py", line 17, in encode
    s = input.read(MAXBINSIZE)
AttributeError: read
-------------------------------------------------------


when i run the small test program -

------------------------------------------------------
base64.test()

Traceback (most recent call last):
  File "C:\Python21\o2db\testmysl.py", line 8, in ?
    base64.test()
  File "C:\PYTHON21\lib\base64.py", line 72, in test
    func(sys.stdin, sys.stdout)
  File "C:\PYTHON21\lib\base64.py", line 17, in encode 
    s = input.read(MAXBINSIZE)
AttributeError: PyShell instance has no attribute 'read'


=================================================================


i'm sure now - murphy was an optimist


fritz
(-:fs)




More information about the Python-list mailing list