At work, I had to save the API that returns image data in base64 format locally. I struggled a little, so a memo (for beginners)
python 3.7.0
data:image/png;base64,iVBORw0KGg.....
splitString =Variable containing the base64 string.split(',')
img_binary = base64.b64decode(splitString[1])
filename='hoge.png'
with open(filename, 'wb') as f:
f.write(img_binary)
Recommended Posts