I'm using a platform that, when you upload pdf's to it, converts the pdf with the base64 encode in Python. Then it stores the binary string in the database.
Now I want to decode the strings and write them to a local folder, so I thought to use the 'with open' structure and pass it the b parameter for binary and then it should create test.pdf based of my decoded string and write it to my desktop? Yet this yields no results, what am I doing wrong here?
code = "My binary string"
with open('test.pdf', 'wb') as fout:
fout.write(base64.decode(code, '~/Desktop'))
EDIT:
code = "My binary string"
with open('~/Desktop/test.pdf', 'wb') as fout:
fout.write(base64.decodestring(code))
Example binary string in database: "65/658e9014babd33786821f3130c5f3a1cc1322ddf" So I'm assuming it starts after the '/' mark?
base64.decode(,)
takes files as args. you want to trythough your code example is not encoded. Here's a working example: