def file_to_attachment(filename, filehandler=None):
 if filehandler:
  return {'_name': filename, 'content': base64.b64encode(filehandler.read())}
 with open(filename, 'rb') as _file:
  return {'_name': filename, 'content': base64.b64encode(_file.read())}

def file_to_attachment ( filename , filehandler = None ) : if filehandler : return { '_name' : filename , 'content' : base64 . b64encode ( filehandler . read ( ) ) } with open ( filename , 'rb' ) as _file : return { '_name' : filename , 'content' : base64 . b64encode ( _file . read ( ) ) }
convert a file to attachment .