Google Drive is a file storage and synchronization service provided by Google which enables user cloud storage, file sharing and collaborative editing.
The storage limit for the free accounts is, at the time of writing, about 5GB.
If you have a blog, like I have, and sometimes you write an article and you want to share a files rather than inserting its contents into the articles page, you could use your free Google account and the Google Drive service to store and share that file.
The problem
The problem that I have encountered regarding this matter was that, when sharing a file you get a public share link, like the one below:
https://docs.google.com/file/d/0B95k2kr1bG9feGVhd0p3QkVCSVE/view
If you provide this address as your HTML link reference then you will not be prompted by the "Save as" window, instead the Google Drive Viewer application will be shown and this will allow you, of course, to download that file:
As we can see in the link provided above, it is structured as following:
- the secure connection protocol : https
- the (sub)domain name : docs.google.com
- other application/directories within the Google website : file/d/
- the file unique identifier : 0B95k2kr1bG9feGVhd0p3QkVCSVE
- the action/command to execute about that file: view (or edit, etc)
If I would write an article and I wish to insert a link to a shared file (stored on Google Drive) I would not be happy to let my readers/visitors to open the Google Drive Viewer then to put them to click one more time, and so on. What I would like to achieve would be to get directly that Save as windows:
Obviously there are (at least) two types of downloads where you really need the direct download link:
- nice to have: on a link inserted on a HTML page (such as a wordpress.com article)
- must to have: on a link where you are supposed to download the file programmatically
In the first case you could live even without the direct link, maybe the Google Drive Viewer it's not such a big deal at the end.
In the second case, if you don't have a direct link, you could end by downloading a content which is not your file but the Google Drive Viewer html content for the requested file:
.config.rpi $ c""0My solution(s)
Obviously, by trial an error, I found two solutions to transparently download from Google Drive:
- For the link you would insert into your web page (such as a wordpress.com article) you could use the following pattern:
- https://docs.google.com/uc?export=download
&confirm=no_antivirus&id=file-id
Ex: https://docs.google.com/uc?export=download&id=0B95k2kr1bG9feGVhd0p3QkVCSVE
- For the link where you are supposed to download the file programmatically the pattern above will not work, instead you will get an error message like below:
root@rpi-gentoo ~ $ --2013-02-23 10:33:32-- https://docs.google.com/uc?export=download Resolving docs.google.com... 173.194.32.3, 173.194.32.4, 173.194.32.5, ... Connecting to docs.google.com|173.194.32.3|:443... connected. HTTP request sent, awaiting response... 500 Internal Server Error 2013-02-23 10:33:32 ERROR 500: Internal Server Error.
I've found that the following pattern will work like a charm:
- https://googledrive.com/host/file-id
Ex: https://googledrive.com/host/0B95k2kr1bG9feGVhd0p3QkVCSVE
Note that in the second case (the one above) the file name you will be prompted to save (programmatically or not) will not be the original shared file name (like in the first example) but the file hashed identifier (such as 0B95k2kr1bG9feGVhd0p3QkVCSVE). Since this method provides a direct link (by the file-id) to download the file programmatically (eg: wget -O URL), it would not be a challenge for any programmer to choose whatever name he/she likes for the output-file.
How to obtain the file-id for the Google Drive file
Open your Google Drive, right-click on your file and then choose Share option. It will open a window like the one below:
The file-id you are looking for is right on the field "Link to share". It is always enclosed between the https://drive.google.com/file/d/ and /edit? parts (eg. 0B95k2kr1bG9faXdzaWNIOGNmSU0).
Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.
Eugen Mihailescu
Latest posts by Eugen Mihailescu (see all)
- Dual monitor setup in Xfce - January 9, 2019
- Gentoo AMD Ryzen stabilizator - April 29, 2018
- Symfony Compile Error Failed opening required Proxies - January 22, 2018
Thanks for this man, really saved my bacon. Wish google would just tell us how to do these stuff so we don't have to have all the pain finding out little hacks like this, and then google can just change it whenever they want and just break it...
well anyway thanks man, also confirming that it still works now.
Thanks, it works!
Thank you it works!
I think this method no longer works 🙁 I get 403 error
If you will try the sample download link that I have mentioned in this article you will see that they are still working. Perhaps you have tested your own links (files) and they are either not shared or you have used a wrong file-id. I have no idea what is wrong with your test.
It was because the file was not downloadable anymore due to the BW limits, Google fixed this bug. Before this method bypassed it that's why it suddenly stopped working
Thanks for sharing this too. Anyway, did you made it working?
I think this works as long as the file "does not exceed the maximum size that Google can scan". For larger files this method gets the html page with that info.
Hi there, when i try to wget a file from my google drive using my rpi, i get the following message:
wget: not an http or ftp url: https://googledrive.com/host/14Tjjz_bIQOZywNIXcQfGSJUZVl0LWOj94PZfKsvbHs0
Have google changed something since your article published or is this something in my rpi not working or have i missed something?
Hi Nathan!
I think that the file-id you've mentioned (14Tjjz_bIQOZywNIXcQfGSJUZVl0LWOj94PZfKsvbHs0) it's the problem. Check again how did you get that file-id, obviously it's not that it should be.
Check out again My Solution(s) section above. It shows you exactly what you have to do. I actually double-checked that those links on "My solutions" section are (still) working as described and they do.
Thanks for sharing this, I created this url https://googledrive.com/host/0BwGVHEf-dgBKUWlEeFIxN3pSVFE witch works fine in browser but if I try with wget:
# wget -c -O minidlna.conf https://googledrive.com/host/0BwGVHEf-dgBKUWlEeFIxN3pSVFE
wget: not an http or ftp url: https://googledrive.com/host/0BwGVHEf-dgBKUWlEeFIxN3pSVFE
Oh, I've just downloaded yours .conf file with exactly the same command and it works like a charm!
So the problem is not the command itself but your proxy, your Internet connection, wget version that you might have installed, etc.
Anyway thanks for sharing your feedback.
You are right, just tried on ubuntu and it works but I need it on my router with entware.
Thanks for pointing me to the right direction
thanks. it works some middle size file, but large size file (ex.1.4GB) don't work,
that page 403 errors..
I just downloaded 1.4GB file without any problem using wget
Commenting over from your other blog. So turns out you can't DL the whole folder in it's entirety, but the good news is that it turns out I was trying to unzip the gz the wrong way. Figured it out and am good to go. Thanks for chatting!
Thanks for this, something so very simple but not made obvious by Google. Quite happily downloaded a 3.3Gb file from Drive to my server using wget
Hi, it seems to me that if you want to access it programmatically, you need to set sharing options (on Drive side) to "everyone could find and access".
With "everyone with link" , it doesn't work.
Unfortunately, this is no longer part of their API.
This doesn't work in 2017. Workaround?
2018: your first [Ex] workaround solution works again, I just downloaded the file ".config.rpi" for a "Linux/arm 3.6.11 Kernel Configuration"