AppsScript- Using an image from Google Drive in HtmlService

前端 未结 3 816
南旧
南旧 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:22

    It sounds like you're trying to offer some sort of permalink from Google Drive that is publicly accessible.

    • Open the File.

    • Under the File Menu, Click Sharing.

    • Under "Who has access", click Change. private

    • Select "Public on the web". sharing options

    • Click done, and copy the link listed. That is your publicly available link which should work for you. public link

    0 讨论(0)
  • 2021-01-21 20:26

    There is not yet a way to do what you are asking.

    0 讨论(0)
  • 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:

    <? getFileBase64s('fileName').forEach(function(fileBase64){ ?>
        <img src="data:image/png;base64,<?=fileBase64?>" >
    <? }) ?>

    0 讨论(0)
提交回复
热议问题