Python 保存 Base64 图片到硬盘

Posted by wxianfeng Fri, 14 Feb 2014 12:53:00 GMT

服务端收到 base64 编码的图片,需要保存到硬盘。

注意需要先把 base64 字符串转为字节,然后使用 base64 的 decodebytes 解出。


with open(tmp_path, "wb") as fh:


1. To convert a string to bytes.
data = ""                    #string
data = "".encode()        #bytes
data = b""                     #bytes

2. To convert bytes to a String.
data = b""            #bytes
data = b"".decode() #string
data = str(b"")         #string

This entry was posted on Fri, 14 Feb 2014 12:53:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags ,


Use the following link to trackback from your own site:


Leave a comment