'Retrieving a raw file URL from the Google Drive API

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.



Solution 1:[1]

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

Solution 2:[2]

Have you tried:

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

(characters)

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nimantha
Solution 2 PARO
Solution 3 Luiz