擅长:python、mysql、java
<p>您只需要将解码后的base64字符串中包含的字节流保存到磁盘。我只是简单地做了以下事情:</p>
<pre><code>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()
</code></pre>
<p>在磁盘中写入后,只需使用文件路径将实例添加/编辑到django中的模型中。在</p>
<p>这对我很有用,希望对我有帮助!在</p>