You can upload any type of file to your Google Drive account and, as of this writing, the storage limit is 15GB. After uploading the file, you can set permissions to define who is allowed to also view and download the file. Alternatively, you can create a folder and set permissions on the folder, which defines the permissions for all the files in that folder automatically. The Google Drive link that is provided for the file takes you to a page in Google Drive to view the file and/or download it manually. That’s a useful feature, but sometimes you may want to bypass the built-in viewer and download the file directly.
Direct Download Link for a Google Drive File
To get the direct download link for a Google Drive file, you can go to the Google Drive developers API references and use their “try it!” API explorer form for the get
API call. In the fileId
field, just paste the file’s ID and click “Execute”. Below under response, in the generated JSON, the direct link that you need is called webContentLink
and looks something like this:
1 2 |
"webContentLink": "https://docs.google.com/uc?id=0ByP7_A9vXm17TmRYcmNScnYzS1E&export=download" |
Download a Googe Drive File in Java
As part of out Datasets project, we need to download some database files that we have on Google Drive from within Java code. Using the direct link from above along with the org.apache.commons.io.FileUtils
class, this can be easily achieved.
1 |
org.apache.commons.io.FileUtils.copyURLToFile("https://docs.google.com/uc?id=0ByP7_A9vXm17TmRYcmNScnYzS1E&export=download", new File("/path/to/dir/"), 5000, 10000); |
Bypassing the Virus Scan Check on Google Drive
Unfortunately, as far as I can tell, this is not possible. There are many posts out there showing how it can be done, but after trying all of them, I’ve come to the conclusion, that Google has disabled this possibilty. As a workaround in our Datasets project, we have built in some logic that directs the client to download the file manually for the files that are too big for Google to run the virus scan on.
5 Comments