title: Upload files in base64 to google drive using Python
body: <p>I'm looking for a code to upload files to google drive using python. Currently I have only the code for authenticacion.</p>
  
  <p><strong>Code V1</strong></p>
  
  <pre><code>    from oauth2client.service_account import ServiceAccountCredentials      
      from httplib2 import Http
  
      #Authentication
      scopes = 'https://www.googleapis.com/auth/drive.metadata.readonly'
      credentials = ServiceAccountCredentials.from_json_keyfile_name('config/key_file.json', scopes)
      http_auth = credentials.authorize(Http())      
      service = discovery.build('drive', 'v3', http=http_auth)
  
      folder_id = 'XXXYYYZZZ'
  </code></pre>
  
  <p>Is it possible? Any idea? thanks</p>
  
  <p><strong>Code V2</strong></p>
  
  <pre><code>    from apiclient import discovery
      from oauth2client.service_account import ServiceAccountCredentials
      from apiclient.http import MediaFileUpload
      from httplib2 import Http
  
      #Authentication
      scopes = 'https://www.googleapis.com/auth/drive.file'
      credentials = ServiceAccountCredentials.from_json_keyfile_name('config/key_file.json', scopes)
      http_auth = credentials.authorize(Http())      
      service = discovery.build('drive', 'v3', http=http_auth)
  
      folder_id = 'XXXYYYZZZ'
  
      f = 'test.html'
      mime = 'text/html'
      body = {
          'name': f,
          'mimeType': mime,
          'parents':   folder_id
      }
      results = service.files().create(
          body=body,
          media_body=MediaFileUpload(f, mimetype=mime, resumable=True)
      ).execute()
  </code></pre>