import base64
# assume 'x' is the variable where you have the base64 encoded image
# 'target.png' is the file name where you'll be saving it
# 'wb' is for a raw binary write operation
fout = open('target.png','wb')
# decode it and write it
fout.write(base64.b64decode(x))
# flush it
fout.flush()
我很确定你需要PIL:
剩下的都是Django的工作,对吧?在
您只需要将解码后的base64字符串中包含的字节流保存到磁盘。我只是简单地做了以下事情:
在磁盘中写入后,只需使用文件路径将实例添加/编辑到django中的模型中。在
这对我很有用,希望对我有帮助!在
相关问题 更多 >
编程相关推荐