2024-03-29 13:45:15 发布
网友
从post请求中,我收到一个JSON格式的base64。问题是我不能将文件类型从string更改为base64,因为它已经格式化为base64。需要base64将其转换回图像。你知道吗
json_data = request.get_json(force=True) img = json_data['img'] print(img) with open("imageToSave.png", "wb") as fh: fh.write(base64.decodebytes(img))
为了对其进行解码,将解码字符串的第三行添加到base64
json_data = request.get_json(force=True) img = json_data['img'] imgdata = base64.b64decode(img) filename = 'upload/newimg.jpg' # I assume you have a way of picking unique filenames with open(filename, 'wb') as f: f.write(imgdata)
为了对其进行解码,将解码字符串的第三行添加到base64
相关问题 更多 >
编程相关推荐