1

I am trying to get the image file URL from the Google Drive API. Not the webViewLink or webContentLink.

The backstory doesn't really matter to the issue but it will help explain the situation. I am making a Discord bot in Node.js and Discord doesn't follow redirects, so I need something that Discord will recognize as a URL with a raw image file. I have tried experimenting with other methods such as trying to send a base64 file, but a image file URL would be best.

I have seen the other StackOverflow thread with a similar topic, but the solutions there don't manage to achieve what I think the author was intending.

Also, I said Discord can't follow redirects, but I could potentially do it server-side, if there is a solution that works.

Kodzvn
  • 45
  • 1
  • 6
  • From `I am trying to get the image file URL from the Google Drive API. Not the webViewLink or webContentLink.`, I cannot understand about your goal. Can I ask you about the detail of it? And, can you provide your current script? – Tanaike Jun 03 '21 at 00:16
  • You can use the `files.get` function in Google Drive API to download the image file by using its ID, and then send the file itself. – kausko Jun 03 '21 at 11:01

3 Answers3

6

Have you tried:

https://drive.google.com/uc?id={file-id}

(characters)

PARO
  • 145
  • 3
  • 13
4

Answer:

This is not possible.

More Information.

Google Drive is not a file hosting service. This is important to remember because it is not designed to allow you to host files for use on your website/app/other. To do this properly you should use a dedicated file hosting service which doesn't rely on the Google Drive environment.

The image URL is obfuscated and not retrievable. The best you can do is use the view or preview links which show only a thumbnail in the discord UI.

View link:

https://drive.google.com/file/d/file-id/view

Preview link:

https://drive.google.com/file/d/file-id/preview
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
2

Try https://drive.google.com/uc?export=download&id=FILE_ID or https://drive.google.com/uc?export=download&id=FILE_ID&confirm=t to bypass the confirmation message

Luiz
  • 143
  • 1
  • 8