通过HtmlService在Apps脚本中提供图像 [英] Serving images in an Apps Script through HtmlService

查看:124
本文介绍了通过HtmlService在Apps脚本中提供图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我确定使用GAS的HtmlService托管和提供图像的最佳方式吗?我正在编写一个应用程序,需要一个带有两个小图像的基本HTML UI,并且我试图尽可能封装所有内容。



当我在原型我的本地机器,我插入图像作为base64编码字符串内联,但它看起来像Caja不支持。



我发现这篇文章关于在Google云端硬盘上托管图像,这将工作为我的目的,但显然驱动器最近弃用该方法:



AppsScript-在HtmlService中使用Google云端硬盘中的图片



我没有请参阅给出文档的任何显而易见的方法,但我强烈不希望在外部服务上托管图像。



https://developers.google.com/apps-script/reference/html/



感谢您的洞察!

解决方案

显示图片使用驱动器托管,将于2016年8月31日停止使用。



Apps Developer Blog



您可以将图像保存到您的Google驱动器,然后使用< img> 标记,并引用source属性中的图片:

 < img src =https://googledrive.com/host/0B12wKjuEcjeiySkhPUTBsbW5j387M/my_image.pngheight =95%width = 95% > 

请注意,您需要使用:

 https://googledrive.com/host/[doc id] 

其中[doc id]替换为文档ID

Google文档链接 - 托管


Can anyone help me determine the best way to host and serve an image using GAS's HtmlService? I'm writing an app that needs a basic HTML UI with two small images, and I'm trying to keep everything as encapsulated as possible.

When I was prototyping on my local machine, I inserted the images inline as base64 encoded strings, but it looks like Caja does't support that.

I found this post about hosting images on Google Drive, which would work for my purposes, but apparently Drive recently deprecated that method:

AppsScript- Using an image from Google Drive in HtmlService

I don't see any obvious way of doing this given the documentation, but I'd strongly prefer not to resort to hosting images on an external service.

https://developers.google.com/apps-script/reference/html/

Thanks for your insight!

解决方案

Note that this way of displaying images uses drive hosting which will be discontinued August 31, 2016.

Apps Developer Blog

You can save images to your Google drive, then use the <img> tag, and refer to the image in the source attribute:

For example:

<img src="https://googledrive.com/host/0B12wKjuEcjeiySkhPUTBsbW5j387M/my_image.png" height="95%" width="95%">

Note that you need to use:

"https://googledrive.com/host/[doc id]

where [doc id] is replaced by the document ID

Google Documentation Link - Hosting

这篇关于通过HtmlService在Apps脚本中提供图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆