i have the following code to convert bunch of bitmap images in a database(binary blob format) to base64 string and store it back into the database.
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.orm import mapper
from sqlalchemy.orm import sessionmaker
import csv
import random
import base64
db = create_engine('mysql://test1:[email protected]:3306/db_moodleerp')
metadata = MetaData(db)
student_photo = Table('tbl_student_photo', metadata, autoload=True)
class StudentPhoto(object):
pass
studentphotomapper = mapper(StudentPhoto, student_photo)
Session = sessionmaker(bind=db)
session = Session()
active_photo = session.query(StudentPhoto).filter(StudentPhoto.is_active==1)
for photo in active_photo:
print photo.student_uni_id
s = base64.b64encode(photo.student_photo_content)
photo.student_photo_content = '\n'.join(s[pos:pos+76] for pos in xrange(0, len(s), 76))
session.add(photo)
session.commit()
The conversion is required for an adobe flex application which expects the images to be encoded in base64. but the problem is with the above way of encoding the application is unable to load the images. Any idea what i am doing wrong here ?