Upload Your File to Google Drive with Python

This article is based on python上傳檔案到Google Drive 怎麼那麼簡單?只要3步驟

Recently I upload a BIG file (about 30GB) to Google Drive. I spent almost 6 hours on it, and the noise of my PC made me hard to sleep.

Frankly speaking, the performance of Google Drive website is pretty slow. When it crashed, we need to re-upload it. It cost us lots of time.

So, in this article I will share you the method to upload file just using Python.

1.Enable the Drive API

Firstly, you should log in your Google Drive(GD) account and go to the following website:

Click “ Enable the Drive API” button and download the credentials.json file.

“credentials.json” is our password to Google Drive API. We should keep it safe.

2.Install Package

Just open your Command line interface and paste the code below:

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib oauth2client


Download the Code from this link

4.Create your folder

In this step, you should create a folder including:
(a) The file you want to upload
(b) credentials.json
(c) quickstart.py (from the link in Step3)

5. Execute quickstart.py

Before we upload our file to Cloud, we should take a look at line 139 of our code, it looks like this:

main(is_update_file_function=bool(True), update_drive_service_name='aaa.txt', update_file_path=os.getcwd() + '/')

we should be aware that the ‘aaa.txt’ is only an example. please change the file name to what you want to upload to.

Once you change your file name, just type the command below to execute the program.

python quickstart.py

and back to your google drive site, you can find that the file has been upload to Google Drive successfully.

Next Step:

I have some project idea:

We can write a E-Book crawler with Python and import the function from quickstart. Once we finish the downloading process, we can upload it to our Google Drive.

I know that some backup softwares are pretty awesome but they are pretty expensive too. Image that you can create your own backup software with Python, you can save lots of money. Also, we can set the program backup your specific location regularly (e.g. Every day at 08:00 am). You can also create GUI with Tkinter. So that we can just click and drag our file to upload to Google Drive.

Final Words:

Hope this article is helpful for you, if you have any questions please don’t hesitate to leave your comment below and I will see you in the next tutorial.

Machine Learning | Deep Learning | https://linktr.ee/yanwei

Love podcasts or audiobooks? Learn on the go with our new app.