def base64_encodefile(fname):
 encoded_f = StringIO.StringIO()
 with open(fname, 'rb') as f:
  base64.encode(f, encoded_f)
 encoded_f.seek(0)
 return encoded_f.read()

def base64_encodefile ( fname ) : encoded_f = StringIO . StringIO ( ) with open ( fname , 'rb' ) as f : base64 . encode ( f , encoded_f ) encoded_f . seek ( 0 ) return encoded_f . read ( )
read a file from the file system and return as a base64 encoded string .