29

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

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
user1459246
  • 291
  • 1
  • 3
  • 3

9 Answers9

15

Yes, you can get a permalink to any file hosted on Google Drive in a public folder. Just note the folderID: Google Drive folder ID 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>

niutech
  • 28,923
  • 15
  • 96
  • 106
11

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.

dmauldin
  • 111
  • 1
  • 4
9

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.

a_guest
  • 91
  • 1
  • 1
  • This solution does not work anymore. I think dropbox in general changed. Overwriting a file changes the url – user42459 Jun 29 '20 at 01:57
8

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!

Salvi Pascual
  • 1,788
  • 17
  • 22
6

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

Adam Szmyd
  • 2,765
  • 2
  • 24
  • 32
4

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

Maruf
  • 890
  • 3
  • 10
  • 21
2

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.

Tomarinator
  • 782
  • 1
  • 11
  • 28
0

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.

Ben K.
  • 449
  • 4
  • 7
0

Not sure if the link generated here is guaranteed to be permanent, but Google Drive Direct Link Generator does the job of generating a direct download link.

Just make sure your file's sharing setting is set to Anyone with the link

Veverke
  • 9,208
  • 4
  • 51
  • 95
  • 1
    worked but after monitoring the http traffic in developer console I see the generated link is invalid and redirected to a valid link – user3840019 Dec 30 '22 at 21:02