import base64import os# base64,参数为文件路径名def file_base64(filepath): if os.path.isfile(filepath): with open(filepath, 'rb') as file: file_base64_str = base64.b64encode(file.read()) return file_base64_str else: return None