下列文件中的图片部分
https://developers.google.com/apps-script/html_service
说,只有托管在公开网址的图像可以显示(由于使用图片代理的)。
这是否适用于存储在用户的谷歌驱动器的图像? 有没有办法使用这些图像作为HtmlService元素?
下列文件中的图片部分
https://developers.google.com/apps-script/html_service
说,只有托管在公开网址的图像可以显示(由于使用图片代理的)。
这是否适用于存储在用户的谷歌驱动器的图像? 有没有办法使用这些图像作为HtmlService元素?
目前还没有一种方法可以做到你的要求。
这听起来像你想从提供谷歌驱动某种永久的可公开访问。
打开该文件。
在文件菜单下,点击共享。
在“谁有权访问”,单击更改。
选择“在网络上公开”。
点击完成,并复制列出的链接。 这是你的公开可用的链接,应该为你工作。
您可以使用基地64编码中嵌入图像。
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;
};
在你的HTML模板:
<? getFileBase64s('fileName').forEach(function(fileBase64){ ?> <img src="data:image/png;base64,<?=fileBase64?>" > <? }) ?>