My solution is like this, took help of drEdit samples:
def get_data(self):
blob_reader = blobstore.BlobReader(self.__blob_key__)
data = blob_reader.read()
fh = io.BytesIO(data)
return fh
def save_file(self, dest_filename, description, mime_type):
service = self.create_drive()
resource = {
'title': dest_filename,
'description': description,
'mimeType': mime_type,
}
try:
file_data = self.get_file_data()
resource = service.files().insert(
body=resource,
media_body=MediaIoBaseUpload(
file_data,
mime_type,
resumable=False)
).execute()
except AccessTokenRefreshError:
pass
calling save_file:
drive.save_file('testing_drive', 'testing....', 'text/csv')
or
drive.save_file('testing_drive.csv', 'testing....', 'text/csv')
However, there one small issue with this code. Google drive API doesn't convert this file to spreadsheet while uploading hence preview doesn't work. To view the file i have to open this doc in spreadsheets which converts the file to google spreadsheet.
I've seen in API documentation regarding the convert option.
However, I couldn't find any way of converting the files while using RPC calls.
Please suggest how can I achieve this.