AppsScript- Using an image from Google Drive in HtmlService

前端 未结 3 817
南旧
南旧 2021-01-21 19:42

The Images section of the following document

https://developers.google.com/apps-script/html_service

says that only images hosted on a public url can be displaye

3条回答
  •  孤街浪徒
    2021-01-21 20:37

    You can embed your images using base 64 encoding.

    function getFileBase64s(fileName) {
      var output = [];
      if (typeof fileName === 'string'){
        var fileIterator = DriveApp.getFilesByName(fileName);
        while (fileIterator.hasNext()) output.push(Utilities.base64Encode(fileIterator.next().getBlob().getBytes()));
      } else {
        SpreadsheetApp.getUi().alert('File name: '+fileName+' is not an string')
      };
      return output;
    };
    

    In your HTML template:

    
        
    

提交回复
热议问题