本文介绍了在“驱动器选择器"小部件中仅显示团队驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个需要提供Drive Picker小部件的应用程序,以便用户可以上传一些文件.现在,我想限制用户,以便他们只能从团队驱动器"中选择文件,而不能从其他任何地方选择文件.

I am creating an application where I need to provide Drive Picker widget so that users can upload some files. Now I want to restrict users so that they can only select files from their "Team Drives" and not from anywhere else.

我尝试在onPickerInit事件中添加方法.

I've tried adding method in onPickerInit event.

这是在onPickerInit事件中被调用的我的函数,

Here's my function which is getting called in onPickerInit event,

function fetchFolder(widget, pickerBuilder) {
  pickerBuilder.addView(new google.picker.DocsView()
                       .setParent('TeamDriveId')
                       .setIncludeFolders(true));
}

此方法限制用户只能从特定的Team Drive中进行选择,但是我的问题是我如何提供动态选项,以便用户可以从其任何Team Drive中进行选择,而不仅限于一个Team Drive.此外,他们也不能从自己的Google云端硬盘中进行选择.

This method restricts users to select only from particular Team Drive, however my question is how can I give dynamic option so that users can select from any of their Team Drives and not limited to one Team Drive. Also they should not be able to select from their own Google Drives.

推荐答案

这种情况下似乎需要对Drive Picker进行低级调整,因此让我们从删除App Maker提供给我们的所有设置开始:

It seems that this case requires low level Drive Picker tuning, so lets start from removing all settings that App Maker gives us out of the box:

  1. 删除所有功能
  2. 删除所有视图
  1. 然后将以下脚本添加到onPickerInit事件
// Enable Team Drives
pickerBuilder.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES);

// Let users to select files from any Team Drive
var multiTeamDrive = new google.picker.DocsView();
multiTeamDrive.setIncludeFolders(true)
              .setEnableTeamDrives(true);
pickerBuilder.addView(multiTeamDrive);


// This feature need to be set to force `setParent` work.
// Seems to be Drive Picker's bug
pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED);

// Force users to upload files to a specific Team Drive
var uploadView = new google.picker.DocsUploadView();
uploadView.setParent('Fancy KEY from Team Drive folder URL')
          .setLabel('Upload to Team Drive XXX');
pickerBuilder.addView(uploadView);

结果

注释

  • 我找不到隐藏个人云端硬盘上传标签的方法.奇怪的是App Maker默认添加它,而没有选择将其删除.
  • 我还建议为用户选择的文件添加服务器端验证,以确保它们源自Team Drive.

类似/相关的答案: https://stackoverflow.com/a/49677679/454137

这篇关于在“驱动器选择器"小部件中仅显示团队驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:59