【问题标题】:What is the substitute for hosting images in google site from Google Drive using Google Apps Script? [closed]使用 Google Apps 脚本从 Google Drive 在 google 站点中托管图像的替代方法是什么? [关闭]
【发布时间】:2016-09-20 07:27:17
【问题描述】:

以前很简单,只是使用网址https://googledrive.com/host/{file_Id},但是,由于网页托管被谷歌停止,问题出现了?

您可以在此处的link 中查看 Google 政策。

【问题讨论】:

标签: google-apps-script google-apps


【解决方案1】:

简答

您仍然可以使用 Google Drive 来托管图片,方法是使用以下 URL 模式:

https://drive.google.com/uc?export=view&id={fileId} 

说明

我认为上述模式是由多个用户通过检查 Google 云端硬盘预览页面或其他类似页面的下载按钮“发现”的。网络上有几篇关于这个“技巧”的帖子,但它并未包含在官方文档中,因此它可能随时停止,而无需 Google 之前的任何公告。

无论如何,这对于某些用途来说可能会很好。

参考文献

Displaying files (e.g. images) stored in Google Drive on a website

【讨论】:

    【解决方案2】:

    首先,我们需要获取存储在驱动器中的字节形式的图像,为此使用应用脚本的 Utilities 类并将其编码为 base64 格式

    var base64_Encoded_Image= Utilities.base64Encode(DriveApp.getFileById('<image id in drive>').getBlob().getBytes());
    

    现在要将此图像添加到&lt;img&gt; 标记中,请使用此

    <img alt='NA' src='data:image/png;base64,"+base64_Encoded_Image+"'/>
    

    【讨论】:

      【解决方案3】:

      您可以将图像托管为免费的 google 站点资源(例如在文件柜或页面附件中)。

      或者,您可以将图像托管在谷歌云存储桶中(但这需要启用项目计费),firebase 也有类似的服务。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多