How to save image in-memory and upload using PIL?
For Python 3.x use BytesIO
instead of StringIO
:
temp = BytesIO()
im.save(temp, format="png")
ftp.storbinary('STOR Obama.jpg', temp.getvalue())
Do not pass a string to storbinary
. You should pass a file or file object (memory-mapped file) to it instead. Also, this line should be temp = StringIO.StringIO()
. So:
temp = StringIO.StringIO() # this is a file object
im.save(temp, format="png") # save the content to temp
ftp.storbinary('STOR Obama.jpg', temp) # upload temp