Convert Google Drive Share Link to Instant Download Link

I'm trying to create a snippet to modify the Google Drive Share link so it forces the file to be downloaded, rather than viewed in Google Drive web interface.

Guidance on method here: How to Get Direct Download URLs from Google Drive

My lack of knowledge is preventing me from troubleshooting my AI assisted attempt at a snippet - I'm guessing my issue is not understanding how to refer to use variables within a snippet.

Any help much appreciated!

{formtext: name=GDriveLink}
{fileId}={regexmatch:{GDriveLink},/d/([a-zA-Z0-9-_]+)/,1}}}

{if: {isempty:{fileId}}}
Invalid Google Drive share link. Please ensure you paste a valid link.
{else}
https://drive.google.com/uc?export=download&id={fileId}
{endif}

1 Like

Hi @Martin_Hill,

I have made the required changes in your snippet, and here is a working version.

{formtext: name=GDriveLink}
{regex="/d/([a-zA-Z0-9-_]+)/"}

{if: not testregex(gdrivelink, regex)}
{error: Invalid Google Drive share link. Please ensure you paste a valid link.}
{else}
{fileId=extractregex(gdrivelink, regex)}
{directLink="https://drive.google.com/uc?export=view&id=" & fileId}
{link: {=directlink}}{=directlink}{endlink}
{endif}

Resources

Amazing, thanks Ashwin!

1 Like

This does not work for me. I am getting error