Google apps script 使用应用程序脚本从文档向Google站点添加图像

Google apps script 使用应用程序脚本从文档向Google站点添加图像,google-apps-script,Google Apps Script,我有一个脚本,允许用户上传图像到谷歌文档,这部分工作,但我需要一种方法来检索图像本身,以便它可以显示在谷歌网站上。我尝试使用doc.getUrl(),但这只返回下载图像的链接。是否有人知道如何实现这一点或其他方式来处理图像上传,这将更好地工作 这是我的代码: function doGet(e) { var app = UiApp.createApplication().setTitle("Upload"); var formContent = app.crea

我有一个脚本,允许用户上传图像到谷歌文档,这部分工作,但我需要一种方法来检索图像本身,以便它可以显示在谷歌网站上。我尝试使用doc.getUrl(),但这只返回下载图像的链接。是否有人知道如何实现这一点或其他方式来处理图像上传,这将更好地工作

这是我的代码:

    function doGet(e) {
       var app = UiApp.createApplication().setTitle("Upload");
       var formContent = app.createVerticalPanel();
       formContent.add(app.createFileUpload().setName('thefile'));
       formContent.add(app.createSubmitButton('Submit'));
       var form = app.createFormPanel();
       form.add(formContent);
       app.add(form);
       return app;
    }

    function doPost(e) {
       var fileBlob = e.parameter.thefile;
       var doc = DocsList.createFile(fileBlob);
       var url = doc.getUrl();
       Logger.log(url);
    }

提前感谢您的帮助。

当您将文件上载到Google Drive时,您无法获得该文件(或您的案例中的图像)的直接链接,因此无法将其嵌入任何位置

解决方案是将图像保存为Google站点页面的附件,然后在Google站点页面中使用该图像


在执行此操作时,还要注意,因为您需要在公共站点上提供图像

如果您可以获得文档ID,则可以创建如下直接下载链接:

https://docs.google.com/uc?export=download&id=doc_id_here
因此,图像嵌入标记:

<img src="https://docs.google.com/uc?export=download&id=doc_id_here" />

不确定下载性能,但应该可以