文件 编码为Base64字符串

参考

import base64

# 读取文件内容并编码为Base64字符串
file_path = 'pdf_ceshi.docx'
with open(file_path, 'rb') as file:
    file_data = file.read()
    file_base64_str = base64.b64encode(file_data).decode('utf-8')

# 打印Base64字符串(或者可以保存到某个地方)
print(file_base64_str)

 

posted @ 2024-08-13 18:47  tslam  阅读(25)  评论(0)    收藏  举报