Google apps script 谷歌工作应用程序-如何创建上传表单,将文件发送到SuperAdmin谷歌硬盘

Google apps script 谷歌工作应用程序-如何创建上传表单,将文件发送到SuperAdmin谷歌硬盘,google-apps-script,google-drive-api,google-apps,google-sites,google-forms,Google Apps Script,Google Drive Api,Google Apps,Google Sites,Google Forms,我在谷歌工作应用程序的30天试用期,我需要创建一个可以从所有域用户访问的表单,但我不能用谷歌表单或谷歌网站,所以我遵循这一点 我用我的个人帐户尝试了这一过程,但当我用GApps SuperAdmin帐户重复这一过程时,它不起作用,我得到了以下错误:异常:拒绝访问:DriveApp。 谷歌脚本 function doGet(e) { return HtmlService.createHtmlOutputFromFile('form.html'); } function uploadFil

我在谷歌工作应用程序的30天试用期,我需要创建一个可以从所有域用户访问的表单,但我不能用谷歌表单或谷歌网站,所以我遵循这一点

我用我的个人帐户尝试了这一过程,但当我用GApps SuperAdmin帐户重复这一过程时,它不起作用,我得到了以下错误:异常:拒绝访问:DriveApp。

谷歌脚本

function doGet(e) {
    return HtmlService.createHtmlOutputFromFile('form.html');
}

function uploadFiles(form) {
  try {

    var dropbox = "Student Files";
    var folder, folders = DriveApp.getFoldersByName(dropbox);

    if (folders.hasNext()) {
    folder = folders.next();
    } 
    else {
        folder = DriveApp.createFolder(dropbox);
    }

    var blob = form.myFile;    
    var file = folder.createFile(blob);    
    file.setDescription("Uploaded by " + form.myName);

    return "File uploaded successfully " + file.getUrl();
  } 
  catch (error) {
      return error.toString();
  }

}
HTML


功能文件上传(状态){
document.getElementById('myForm').style.display='none';
document.getElementById('output')。innerHTML=status;
}
输入{显示:块;边距:20px;}
这是我的“部署为Web应用”配置:


我愿意接受所有建议,不必使用谷歌脚本如果有更可靠的道路

请查看此链接,它在应用程序脚本环境中使用谷歌选择器-因此提供了一个漂亮流畅的用户界面和进度条等

主要的警告是,选择特定的上载文件夹需要启用多个上载

您需要稍微更改它以添加上传视图,如下所述

function createPicker(token) {
    if (pickerApiLoaded && token) {
      var uploadView = new google.picker.DocsUploadView();
      uploadView.setParent(FOLDERID); //PUT FOLDER ID HERE!!!
      var picker = new google.picker.PickerBuilder()
          // Instruct Picker to display only spreadsheets in Drive. For other
          // views, see https://developers.google.com/picker/docs/#otherviews
          .enableFeature(google.picker.Feature.MULTISELECT_ENABLED) //disable this and documents will end up in users root directory
          .addView(uploadView)
          // Hide the navigation panel so that Picker fills more of the dialog.
          .enableFeature(google.picker.Feature.NAV_HIDDEN)
          // Hide the title bar since an Apps Script dialog already has a title.
          .hideTitleBar()
          .setOAuthToken(token)
          .setDeveloperKey(DEVELOPER_KEY)
          .setCallback(pickerCallback)
          // Instruct Picker to fill the dialog, minus 2 pixels for the border.
          .setSize(DIALOG_DIMENSIONS.width - 2,
              DIALOG_DIMENSIONS.height - 2)
          .build();          
      picker.setVisible(true);
    } else {
      showError('Unable to load the file picker.');
    }
  }
我的特定用例是一次上传,因此我必须编写一些额外的代码来将文件移动到指定的文件夹中——这很简单,tho:)

当作为web应用程序进行测试时,请确保对“最新代码”使用测试web应用程序在发布->部署为WEB应用下找到…


当您准备好共享时,您必须创建一个新版本并发布该版本!这让我很吃惊,如果你的新版本是:D-在文件->管理版本下找到…并保存新版本,然后发布->部署为WEB应用程序…并从下拉列表中选择新版本,这就不那么明显了。

我尝试了代码,在打开其中一条评论中提到的Google drive apps@Greg后,它对我起了作用

有关管理控制台中的此设置,请转到: 谷歌应用>硬盘>常规设置>,然后选中“允许用户安装谷歌硬盘应用”框

此外,使用此代码,文件将存储在当前用户的驱动器中,而不是管理员的驱动器中。要解决此问题,您必须满足以下条件:

  • 在管理员的驱动器中创建文件
  • 复制文件夹ID
  • 在Appscript中,使用以下方法 'var folder=DriveApp.getFolderById('文件夹ID');' -您不需要代码来创建文件夹,因为这里已经完成了
  • 该文件夹需要与用户共享
  • 用户将需要请求访问权限

希望对您有所帮助。

从脚本编辑器运行doGet以获取已尝试过的授权请求对话框,我遵循的指南解释此步骤是否在您的域中启用了允许第三方驱动器应用程序设置?在哪里可以找到此设置?
function createPicker(token) {
    if (pickerApiLoaded && token) {
      var uploadView = new google.picker.DocsUploadView();
      uploadView.setParent(FOLDERID); //PUT FOLDER ID HERE!!!
      var picker = new google.picker.PickerBuilder()
          // Instruct Picker to display only spreadsheets in Drive. For other
          // views, see https://developers.google.com/picker/docs/#otherviews
          .enableFeature(google.picker.Feature.MULTISELECT_ENABLED) //disable this and documents will end up in users root directory
          .addView(uploadView)
          // Hide the navigation panel so that Picker fills more of the dialog.
          .enableFeature(google.picker.Feature.NAV_HIDDEN)
          // Hide the title bar since an Apps Script dialog already has a title.
          .hideTitleBar()
          .setOAuthToken(token)
          .setDeveloperKey(DEVELOPER_KEY)
          .setCallback(pickerCallback)
          // Instruct Picker to fill the dialog, minus 2 pixels for the border.
          .setSize(DIALOG_DIMENSIONS.width - 2,
              DIALOG_DIMENSIONS.height - 2)
          .build();          
      picker.setVisible(true);
    } else {
      showError('Unable to load the file picker.');
    }
  }