I’m working on a project where I need to show images stored in Google Drive on my HTML page through Apps Script. I’ve been struggling with this for a while now and can’t seem to get it right.
Here’s what I attempted:
<img src="https://drive.google.com/file/d/fileID/view" alt="My Picture">
But this approach doesn’t display the image properly. The image either doesn’t load or shows an error.
I’ve also tried different URL formats but none seem to work as expected. Has anyone successfully implemented this before? What’s the correct way to reference Google Drive images in HTML when using Apps Script? Any help would be greatly appreciated.
yeah, the uc?id= format works but add &export=download at the end if you’re getting caching issues. also watch your file size - drive has limits for direct embedding and shows a preview page instead of the actual image if it’s too big. found this out the hard way with some hi-res photos that kept breaking.
Permissions matter, but I found something that works way better in production. Skip the direct Google Drive URLs and use Apps Script to serve images through a web app instead. Set up a doGet function that grabs the blob from Drive and returns it with the right headers. This gets around sharing restrictions and lets you control caching however you want. I built this for a client portal where we couldn’t make files public. Performance was actually better than direct Drive links since you can add your own caching and handle errors properly.
This happens all the time with Google Drive images in Apps Script. You’re using the view URL, but you need the direct link format: https://drive.google.com/uc?id=fileID. Just swap out the URL format and you should be good.
But here’s the catch - your Drive file needs to be shared as ‘Anyone with the link can view’ or it won’t work. I spent hours debugging this exact issue last year on a dashboard project before figuring out the sharing settings were blocking everything.
One more thing - Google throttles these requests sometimes. If you’re loading tons of images, you might want to use the Drive API directly through Apps Script instead. Gives you way more control.