代码之家  ›  专栏  ›  技术社区  ›  Jeroen at ihello

使用DrivePicker时,获取webcontent链接

  •  0
  • Jeroen at ihello  · 技术社区  · 7 年前

    在表格上我放了一个 DrivePicker 小部件/按钮。这个按钮打开我的谷歌驱动器,我可以选择一个图像。在中显示此图像 Image 我需要webcontent链接而不是文件URL链接。文件URL链接无效。

    驱动器选择器 我把下面的代码放在 onDocumentSelect 部分

    varId = result.docs[0].id;
    widget.datasource.item.strArtikelAfbeeldingId = result.docs[0].id;
    widget.datasource.item.strArtikelAfbeeldingUrl = Drive.Files.get(varId).webContentLink;
    

    未定义驱动器 在pageTabelArtikelen。表格1.1正文。驾驶员选择器1。onDocumentSelect:3:50

    使用时如何获取选定图像的webcontentlink 驱动器选择器 小装置?

    1 回复  |  直到 4 年前
        1
  •  0
  •   Markus Malessa    7 年前

    您需要从客户端运行服务器函数才能使用驱动器。因此,您仍然可以为onDocumentSelect事件运行此函数,但您需要声明一个服务器函数,例如getFileWebContent(),然后将事件代码更改为:

    客户

    var Id = widget.selectedDocId;
        google.script.run
          .withSuccessHandler(function() {
          //do something here with the returned link from server;
          })
          .withFailureHandler(function() {
          //optional failure handler;
          })
          .getFileWebContent(Id);
    

    服务器

    function getFileWebContent(Id) {
      var link = Drive.Files.get(Id).WebContentLink;
      return link;
    }
    

    更理想的做法是在作为服务器函数的onCreate事件模型中运行服务器代码。在这种情况下,您的模型可以有一个文件id字段,并在onCreate事件中运行

    var link = Drive.Files.get(record.FileId).webContentLink;
    record.WebLink = link;