Google Drive direct download link creation for shared files

Google Drive Direct Download Link

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": "",
  "webContentLink": "",
  "alternateLink": "",
  "iconLink": "",
  "thumbnailLink": "",
  "title": "2012-02-08_15.50.19.jpg",
  "mimeType": "image/jpeg",
  "downloadUrl": "",
  "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.{FileID}&export=download

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

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

-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.

10 responses to “Google Drive direct download link creation for shared files”

  1. How can you do this with a large file? .dmg, .exe where it asks you to click on a ‘downaload anyway’ after you put in the url?

Leave a Reply

Your email address will not be published. Required fields are marked *