I found this question, trying to figure out where the "MediaFileUpload" came from from the Google API examples, and I finally figured it out. Here is a more complete sample code that I used to test using Python 2.7.
You need a JSON credential file for this code to work. This is the credential file that you get from your Google app / project / stuff.
You also need a file to download, I use "test.html" here in the example.
from oauth2client.service_account import ServiceAccountCredentials from apiclient.discovery import build from apiclient.http import MediaFileUpload
The list of valid Mime types for use in the "body" hash is available at https://developers.google.com/drive/v3/web/mime-types
The list of valid mimetype lines for MediaFileUpload (they will try to convert your file to what you put here):
https://developers.google.com/drive/v3/web/integrate-open#open_files_using_the_open_with_contextual_menu
Locane
source share