pythongoogle-drive-apigoogle-drive-realtime-api

Unable to upload a file to Google Drive


I want to be able to upload a file inside my hard disk to Google Drive using program as follows:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)
this_file = 'apple.txt'
this_file.Upload()

However, I got the following error:

AttributeError: 'str' object has no attribute 'Upload'

How can I upload it?


Solution

  • The example here says to do this:

    this_file = drive.CreateFile()
    this_file.SetContentFile('apple.txt') # Read file and set it as a content of this instance.
    this_file.Upload() # Upload it