【发布时间】:2016-10-23 16:06:30
【问题描述】:
我正在尝试在 google 驱动器中获取 png 图像以显示在 google 应用程序脚本 html 页面上。如果图像只是在网络上某处的 URL 上,我可以让图像出现在脚本 html 页面上(见下面注释掉的行),但不是来自谷歌驱动器。这是我试图将其作为 blob 获取然后在图像标签中使用的代码的一部分:
function getImage() {
//The next 2 lines don't produce the image on the page
var image = DriveApp.getFileById('File Id Goes Here').getBlob().getAs('image/png');
var image = '<img src = "' + image + '" width = "90%">'
//Note, the next line uncommented produces an image on the page
//var image = '<img src = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width = "90%">'
return image
}
function doGet() {
var htmlToAppend = getImage();
var html = HtmlService.createTemplateFromFile('index').evaluate()
.setTitle('Google Image').append(htmlToAppend).setSandboxMode(HtmlService.SandboxMode.IFRAME);
return html;
}
结果是脚本生成的 html 页面上缺少图片,缺少图片的 URL 以 script.googleusercontent.com/Blob 结尾
关于 Blob 的信息在这里:https://developers.google.com/apps-script/reference/base/blob(在单独的页面/选项卡中打开)
感谢任何帮助。
【问题讨论】:
标签: javascript google-apps-script