5

How to get the direct download link of a file by google drive api v3 in java ?

Hi all, I've worked with Google Drive Api in Android for a week, I used both Android Drive SDK and Drive Rest Api for java but I can't find the way how to how to get the direct download link of a file (anyone can read) on Drive. I've try How to get the url of a file of google drive to download in android but it's not work. Please help me. Thanks.

Community
  • 1
  • 1
Hưng
  • 88
  • 1
  • 9

2 Answers2

12

Given that you have the actual FILE-ID for the file , you can download it using the download link

drive.google.com/uc?id=FILE-ID&export=download

1

If you want to have the direct download link of a file, DriveFile doesn't seem to be what you're looking for. What you can do is to use the Drive API web service instead. Note that you're still required to be authenticated for you to use the API.

Check out the Download Files section of the documentation, there are 3 ways for you to download the file.

Another alternative is for you to use the webContentLink for you to download the file. However, this is only available for files with binary content in Drive.

adjuremods
  • 2,938
  • 2
  • 12
  • 17
  • instead of webContentLink use webViewLink. If the file is binary or unable to be loaded directly you will get a Download or Open with screen in the browser. – rob Dec 09 '21 at 17:48