fixed in memory file saving and base64 encoding for python 3

Fixed py3k and tested on linux. Other OS should work fine.