What is the substitute for hosting images in google site from Google Drive using Google Apps Script? [closed]

夙愿已清 提交于 2019-12-06 07:35:52
Yash Gupta

First, we need to get the byte form of image stored in the drive, to do that use Utilities class of app script and encode that in base64 format

var base64_Encoded_Image= Utilities.base64Encode(DriveApp.getFileById('<image id in drive>').getBlob().getBytes());

now to add this image in <img> tag use this

<img alt='NA' src='data:image/png;base64,"+base64_Encoded_Image+"'/>
Rubén

Short answer

You could still use Google Drive to host images, by using the following URL pattern:

https://drive.google.com/uc?export=view&id={fileId} 

Explanation

I think that the above pattern was "discovered" by several user by inspecting the download button from the Google Drive preview page or another similar page. There are several posts around the web about this "trick", but it's not included in the official documentation so it could stop at any time without any previous announcement by Google.

Anyway, this could could serve well for some purposes.

References

Displaying files (e.g. images) stored in Google Drive on a website

you may host the image as a google site resource (in a file cabinet or page attachment for example) which is free.

alternatively, you may host the image in a google cloud storage bucket (but that requires to enable project billing) and firebase also has a similar service.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!