How to download large files from Google Drive using Google’s Drive API!

Patrick Aziken
3 min readOct 10, 2021

--

Have you tried downloading large files from Google Drive quota limits, timeouts or wget issues?

You are not the first and won’t be the last 😬! Thanks to Google’s Drive API, you’ll be just fine.

Difficulty Level: Very easy

Here’s how to do it:

1] Get the file ID: Navigate to google drive, right-click on the file in question (not a folder) and click on “Get Link”. The link may look like this “https://drive.google.com/file/d/FILEID/view?usp=sharing”.

The part “FILEID” above is the ID that we need. It’s a bunch of random alphanumeric characters. Take note of it. It will save your life in the coming steps 😜

2] Now we use Google’s OAuth Token from the OAuth Token Playground. Click the link to jump there.

3] Choose a scope: You must choose the scope from the API list. What we need is something to read/write to/from Google Drive. Scroll in that list and search for Drive API v3 (at the time of this writing). Expand the scope and choose “https://www.googleapis.com/auth/drive.readonly”

Select Drive API v3 from the scope in Google OAuth Playground.

4] Click the “Authorize APIs” button

Click the Authorize APIs button

Your browser may prompt you to choose a google account if you are not signed in or if you are signed in to multiple google accounts. Choose your Google Account. It does not matter which one. Allow access to the account if prompted to do so.

5] Click the “Exchange authorization code for tokens” button. A token will generated once you click the button.

Click Exchange code for tokens

6] Copy the access token. This again will save your life, for the next 3600 seconds, after which it expires…the token that is 😜

7] If you are using OS X or Linux, copy the code below into a note first:

curl -H “Authorization: Bearer XXXXX” https://www.googleapis.com/drive/v3/files/FILEID?alt=media -o YYYYY

If you are a Windows user, copy the code below into a note first:

Invoke-RestMethod -Uri https://www.googleapis.com/drive/v3/files/FILEID?alt=media -Method Get -Headers @{“Authorization”=”Bearer XXXXX”} -OutFile YYYYY

XXXXX: this is the access token you generated

FILEID: this is the ID of the file we want to download from Google Drive

YYYYY: this is the name we want to use to save the file e.g. myproject.iso or myweddingvideo.mp4 or mywebproject.zip

8] Press “Enter” on your keyboard and your file should start downloading!

You can enable the Auto Refresh Token if your file is going to take longer to download.

One trick… if you do not have fast internet but you have access to a server with some space and want to be able to grab the file before it hits quota limits, use it, then you can download the file to your computer at a later time. At least you have the file you need and can download it whenever without too many restrictions. Just so you know, this method may use out of your servers allocated bandwidth when downloading directly to the server, so don’t do this if you are on a limited bandwidth and/or storage space or if it breaches your hosting provider’s policy.

Just to give you an idea, it took 5 minutes to download a file of 11.4GB into my server. Of course I spent another 30 minutes downloading from my server to my computer much later 🚄

Download speed for a large file

By now, your 150 billion petabyte file should have download successfully…in one hour…or…not? 😬

Pssst: If you like what you have read, can you give me some claps and share it too, please? 🥺 🙏🏻

--

--

Patrick Aziken

Father, husband, technology advocate, software tester, web designer.