File creation is forbidden in Google App Engine standard applications.
Even tempfile is disabled, except for TemporaryFile which is aliased to StringIO. So I need to set content of drive file with a StringIO object.
The only suitable method I found is SetContentString().
But the method is expecting a utf-8 string and I get a decode exception -
UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in range(128)
My code
drive = GoogleDrive(get_drive_auth())
drive_file = drive.CreateFile()
drive_file.SetContentString(stringio_object.getvalue())
Is there a way I could set the content of a GoogleDrive
object from StringIO
object?
I got answer on GitHub.
It is not documented, but you can set content of GoogleDrive object directly
drive = GoogleDrive(get_drive_auth())
drive_file = drive.CreateFile()
drive_file.content = stringio_object