Search code examples
google-apps-scriptgoogle-apps

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


It was very simple before, simply using the URL https://googledrive.com/host/{file_Id} but, the problem arises because the web page hosting is being discontinued by Google?

You can check the Google Policy in the link here.


Solution

  • 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+"'/>