import os import base64 fileSize = os.path.getsize(檔案路徑) with open(檔案路徑, 'rb') as f: data = base64.b64encode(f.read())