在表单上我放了一个DrivePicker小部件/按钮。这个按钮打开我的谷歌硬盘,我可以选择一个图像。要在Image小部件中显示此图像,我需要webcontent链接而不是文件url链接。文件网址链接不起作用。
通过DrivePicker小部件的属性编辑器,我将下面的代码放在onDocumentSelect部分。
varId = result.docs [0] .id; widget.datasource.item.strArtikelAfbeeldingId = result.docs [0] .id; widget.datasource.item.strArtikelAfbeeldingUrl = Drive.Files.get(varId).webContentLink;
不幸的是,我没有获得webcontentlink并得到了以下错误消息
未定义云端硬盘 at pageTabelArtikelen.Form1.Form1Body.DrivePicker1.onDocumentSelect:3:50
使用DrivePicker小部件
时,如何获取所选图像的webcontentlink答案 0 :(得分:0)
您需要从客户端运行服务器功能才能使用Drive。因此,您仍然可以为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;