Is is possible to get a permanent URL to a file uploaded to Google drive?

I can't find the answer to this in the API docs or elsewhere. I see in the docs says you can get a downloadURL of a file, but it refers to it as a 'short lived URL'. What does that mean?

I need to upload images and get a permanent URL of that image that is the direct URL than can be embedded into emails or web docs etc. Is that possible?

Thanks

Answers


Yes, you can get a permalink to any file hosted on Google Drive in a public folder. Just note the folderID: and paste it to the following URL: http://googledrive.com/host/<folderID>/<filename> or you can create a short custom alias using G Drives: http://gdriv.es/<alias>/<filename>


https://developers.google.com/drive/v2/reference/files#webContentLink

downloadUrl is short lived, but webContentLink is a permanent link. It's odd that one is a URL and the other is a "link", but I guess it probably has to do with the additional query params in the strong. Maybe that makes it not just a URL? :)

That property is only available for files that are publically readable, so you may have to use the SDK/API to set the permissions first.


In case someone encounter the same problem and don't want to do with deprecated Google Drive solution above and requires frequently changed files with exact same url, you can use Dropbox. Steps:

  • Download the program and share a folder (tutorial)
  • Copy a file into that folder; wait for sync with Dropbox
  • Go to your dropbox.com account
  • Share your file by button, get something like: https://www.dropbox.com/s/d28d8scvr3rfy48/foo.exe?dl=0
  • Rename it to: https://dl.dropboxusercontent.com/s/d28d8scvr3rfy48/foo.exe?dl=0

Now you have a public, unchanged url for all your foo.exe changes. Enjoy, don't waste time with sites offering you file hosting and they change the URL for same files.


I don't know how often this changes but I was looking for a dynamic solution where I wouldn't need to manually upload to another site and the provided solutions weren't working.

Here's the url that worked for me:

https://lh3.google.com/u/0/d/<file_id>

Where file_id is the getId() using the google apps script drive API. Secondly the file must be shared publicly like posted previously

Secondly I imagine the lh3 are different cdn's though I cannot confirm since lh1/2 don't work and everything higher than 3 redirects to lh3


I don't know if such API for google drive exists, but I think you should also have a look at dropbox, which will meet all the demands that you mention in your question.

Also there are some very cool applications developed just for dropbox, like pancake.io which lets you share links of text, html files, in an html page format.

that + permanent link is always there.


If you share a file publicly in GDrive, you can use the following link to make the file download directly:

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

The problem happens when you want to change the file (for version controlled download, in instance) and keep the same downloading link.

You can use a URL Shortener like bitly.com and use a Branded Bitlink to change the destination URL keeping the input URL.

I hope it works, good luck!


You can use gdriveurl.com, it got updated and now allows users to log in with their google drive account and share the list of files instantly, getting for each file "View" & "Download" short permalink.

There's also the old solution (login to Google Drive, set everything to "Public on web", copy share link, convert it into the gdriveurl.com textarea in the homepage), but it's just a waste of time, you should try "MyDrive" api.


It seems if you have file ID you can access it with such url:

https://drive.google.com/open?id=file-id-here

If file is public, you'll see it immediately but if not, you're be asked to login


Need Your Help

Why is it not a good idea to use SOAP for communicating with the front end (ie web browser)?

javascript soap

Why is it not a good idea to use SOAP for communicating with the front end? For example, a web browser using JavaScript.