从post请求中,我在JSON中收到了一个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))
从post请求中,我在JSON中收到了一个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))
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)