def send_file(self, filepath):
"""
Send a base64 encoded string to the server.
:param filepath: string path to file
:return: None
"""
_, tail = os.path.split(filepath)
print str(self.username) + " sending out " + str(tail)
fh = open(filepath, 'rb')
content = base64.b64encode(fh.read())
payload = self.new_payload()
payload['content'] = content
payload['type'] = constants.FILE
payload['filename'] = os.path.basename(filepath)
# Send the payload as a binary message by marking binary=True
self.send(str(json.dumps(payload)), True)
# Avoid feedback
time.sleep(0.2)
fh.close()
# self.close()
评论列表
文章目录