All the documentation I have found related to creating a new file and putting the new file in a user's Google Drive folder is achieved with the user uploading a file and having the python script use MediaFileUpload to gather the file and put it in Drive.
I want to create a new file in my GAE code, and put that. For example my code renders a new XML string after hitting database, and I would like to take that string, make it a file and put in Google Drive.
Anyone working with something like this?
Google offers Backup and Sync, an application you can install on your computer in order to back up any folder on your computer over to Google Drive automatically. Simply install Backup and Sync and you can add any folder on your computer to automatically upload all files to Google Drive.
To create a folder, use the files. create method with the application/vnd. google-apps. folder MIME type and a title.
You should use a MediaInMemoryUpload instead, which is designed for this exact purpose. You can pass a string and a MIME type.
media = MediaInMemoryUpload('some data', 'text/plain')
Use following code, content is the string you're going to put. You don't have to use MediaFileUpload and python client library.
def update(content, file_id):
url = 'https://www.googleapis.com/upload/drive/v2/files/%s?uploadType=media' % file_id
headers = {
'Content-Type': 'text/plain',
'Content-Length': str(len(content)),
'Authorization': 'Bearer <oauth2 token>'
}
response = urlfetch.fetch(url, payload=content, method='PUT', headers=headers)
assert response.status_code == 200
return response.content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With