When sharing files on Google Drive the link provided isn’t a direct link to download the file. Instead, it’s link to a view page for the file where you are then provided with the option of downloading the file. This isn’t great if you’re using the command line.

Google Drive File ID

After digging around the Google Drive API documentation, I came across their API Explorer which let me run a GET request using my file’s ID which was the string of characters that were part of the original sharing link. This can be used to create a Google Drive direct download link.

Google Drive File ID

The API Explorer returned a JSON object containing detailed information about my file.


 "kind": "drive#file",
 "id": "0B4fIuYID3dr-aHY2eS1NcHdMeEU",
 "etag": ""clAeecEUyj02g11ejAUBi6k3Qow/MTQwNTg2Nzg3ODUxOQ"",
 "selfLink": "https://www.googleapis.com/drive/v2/files/0B4fIuYID3dr-aHY2eS1NcHdMeEU",
 "webContentLink": "https://docs.google.com/uc?id=0B4fIuYID3dr-aHY2eS1NcHdMeEU&export=download",
 "alternateLink": "https://docs.google.com/file/d/0B4fIuYID3dr-aHY2eS1NcHdMeEU/edit?usp=drivesdk",
 "iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_11_image_list.png",
 "thumbnailLink": "https://lh5.googleusercontent.com/ZjjefSIS2J0EL7VCaAVgGGHVI7pGBXDlP6SxS1Yaf8-DRXPvmQyTyGHOwsNko4lvACNTmg=s220",
 "title": "2012-02-08_15.50.19.jpg",
 "mimeType": "image/jpeg",
 "downloadUrl": "https://doc-0g-5k-docs.googleusercontent.com/docs/securesc/o7l0aeqi0drljltr83c3565k9441n6of/ouvkclo2c8f1le8fef5jhi1bfipkhs3u/1405864800000/18051092305914045301/13058876669334088843/0B4fIuYID3dr-aHY2eS1NcHdMeEU?h=16653014193614665626&e=download&gd=true",
"md5Checksum": "af375ee3952fa29344abe2067cf84b78",
 "fileSize": "54869",

Google Drive Direct Download Link

The downloadUrl could be helpful but it would clearly be a hassle for my purposes and the resource documentation states the URL is short lived. What I really want to use for direct downloads is the webContentLink.


You can switch docs for drive and &export=download doesn’t appear to be necessary.


Testing Direct Download Link

Since the visibility for my file is set to Anyone with the link, I can easily download the file using cURL without having to worry about authentication (Public on the web works as well).

curl -O -J -L https://drive.google.com/uc?id=0B4fIuYID3dr-aHY2eS1NcHdMeEU

-O and -J together save the file using the server-specified filename rather than basing it on the URL. -L has cURL follow the redirects it will encounter when accessing our link.

You should now have a working Google Drive direct download link. If you ran into problems, please post in the comments.

%d bloggers like this: