Direct download links from Google Drive

Sometimes, you need to host or stage a file on Google Drive and make that file acessible to a non-human (um, another computer). Unfortunately, the “shareable” link that you can generate from the Google Drive interface requires a human to navigate via a web-browser to the Google Drive interface, and then select the “download” button on the web-page – this is difficult, if not impossible, for computer code to handle correctly. There is a way, however, to use the information found in the “shareable” link to compose a new URL that points directly (sort of - see caveats below) to that file. The critical (and only) information that you need from the shareable link is the file identifier, which can be used to compose a new URL that points directly to the file on Google Drive. This new URL pattern is:

https://drive.google.com/uc?export=download&id=FILE_IDENTIFIER

Here are the guided steps to compose the new URL.

Step 1 From the Drive interface “right click” on the file you want to access and select “Get sharable link”. This will copy the shareable link URL to your computer’s clipboard and, importantly, make the file publicly accessible.You can also highlight the file and set the sharing a bit more manually by opening the “sharing” dialog window and creating/copying the “shareable link”.

Step 2: In a text editor on your computer, paste in the “shareable” link and copy the file identifier string from the URL. For example, the following shareable link URL

https://drive.google.com/open?id=17zRtySAIzrlcY4pi4TX4yJpq9JdLNq_w

indicates that the file identifier is 17zRtySAIzrlcY4pi4TX4yJpq9JdLNq_w.

Step 3: Copy the file identifier from the “shareable” link and replace the FILE_IDENTIFIER text in the new URL with the copied identifieir:

https://drive.google.com/uc?export=download&id=17zRtySAIzrlcY4pi4TX4yJpq9JdLNq_w

That’s it! Now you have a direct link to a file from Google Drive. Try it out by using curl or wget in a command line shell:

curl -s -L -X GET "https://drive.google.com/uc?export=download&id=17zRtySAIzrlcY4pi4TX4yJpq9JdLNq_w"

Note: For large files, you may need to insert &confirm=no_antivirus into the new URL just before the &id:

curl -s -L -X GET "https://drive.google.com/uc?export=download&confirm=no_antivirus&id=17zRtySAIzrlcY4pi4TX4yJpq9JdLNq_w"

I’ve tried to find more information about the https://drive.google.com/uc end-point, but have drawn a blank. If anyone has additional information on this interface, please post a comment.

Caveats

  1. The file you want to share must be one that you uploaded from your computer - it cannot be an object created on Google Drive (e.g., Docs, Sheets, Slides, etc…).
  2. The new URL you create will result in 302 redirect to yet another URL, so your computer code that accesses this file must be able to handle HTTP redirects.
  3. The new URL pattern has been consistent since 2004; Google may change this pattern at any time and without warning, so your mileage may vary.

Endnote…

This post is a mashup of various articles and other posts found through, yes, Google. The most informative of these is by Milan Aryal, who describes direct links to Dropbox, Google Drive, Google Docs, and Microsoft’s OneDrive. Other than Google Drive, I have not tested these other approaches. For this, I’ll just leave as an exercise to the reader.