[Answer]-How do I encode/decode a file correctly after reading it through javascript and pass the file data through ajax?

1👍

✅

You got error because Python 2‘s default ASCII encoding was used. Characters greater than 127 cause an exception so use str.encode to encode from Unicode to text/bytes.

Good practice is to use with keyword when dealing with file objects.

path = u''.join((file_path, user_org, '_', fileName)).encode('utf-8')
with open(path, 'w+') as f:
    f.write(fileData)

Leave a comment