""" 上传json格式,base64数据文件。 """
import time
import json
import base64
import requests
def get_base64str(file_path):
"""获取base64位字符串 bytes字节 -->base64字节 --> base64字符串 """
str_base64 = None
with open(file_path,'rb') as f:
bytes_base64 = base64.b64encode(f.read())
str_base64 = bytes_base64.decode('utf-8')
assert str_base64 is not None
return str_base64
def save_file(str_base64,topath):
"""将base64还原存储为文件, 查看文件是否能正常打开, 以确认编码正确. """
bytes_base64 = str_base64.encode('utf-8')
with open(topath,'wb') as f:
_bytes = base64.b64decode(bytes_base64)
f.write(_bytes)
if __name__ == '__main__':
"""请求调用API"""
data = { "filetype":"base64","file":""}
data["file"] = get_base64str("test.mp4")
url = "http://192.168.56.102/api/verify"
headers = { "Content-Type":"application/json"}
res = requests.post(url=url,headers=headers
data=json.dumps(data),timeout=(3.05,15))
print(res.text)
还没有评论,来说两句吧...