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.
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.
https://docs.google.com/uc?id={FileID}&export=download
You can switch docs for drive and &export=download doesn’t appear to be necessary.
https://drive.google.com/uc?id={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 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.
10 responses to “Google Drive direct download link creation for shared files”
Thank you. This really helped me a lot.
Thanks so much
Life saver… Thanks!!!! Why doesn’t one of the Google API’s return THAT???
its not working now
Simply:
Change: https://drive.google.com/file/d/FILE_ID/edit?usp=sharing
To: https://drive.google.com/uc?export=download&id=FILE_ID
Replace File ID like the above article says, this has been working since 2014 till now.
yes, it’s not working any more
How can I get the id of the files that are constantly being generated within google drive, not to be one by one?
Thanks yes working good for me :=)
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?
thanks alot… its working fine… what about multiple downloads at a time. i.e if i select multiple files.