Google Drive API V2, Python - create a new file without uploading a new file and without using the Google Drive user interface

All the documentation I found related to creating a new file and placing the new file in the Google Drive user folder is achieved when the user loads the file and uses a python script to use the MediaFileUpload file to collect it in Drive.

I want to create a new file in my GAE code and put it. For example, my code displays a new XML line after getting into the database, and I would like to take this line, make it a file and put it on Google Drive.

Does anyone work with something like this?

+5
source share
2 answers

MediaInMemoryUpload, . MIME.

media = MediaInMemoryUpload('some data', 'text/plain')
+4

, - , . MediaFileUpload python.

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
+1

All Articles