0

我處於Google Apps for Work的30天試用期,我需要從所有域用戶創建FORM Accessable,但我可以「T與谷歌表單或谷歌網站做,所以我遵循這個guideGoogle Apps for Work - 如何創建向SuperAdmin Google Drive發送文件的上傳表單

我嘗試這與我的個人賬戶和它的作品,但是當我重複此過程GAPPS超級管理員帳戶它不工作,我得到這個錯誤:例外:訪問被拒絕: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

<form id="myForm"> 
    <input type="text" name="myName" placeholder="Your name.."> 
    <input type="file" name="myFile"> 
    <input type="submit" value="Upload File" 
      onclick="this.value='Uploading..'; 
        google.script.run.withSuccessHandler(fileUploaded) 
        .uploadFiles(this.parentNode); 
        return false;"> 
    </form> 

    <div id="output"></div> 

    <script> 
     function fileUploaded(status) { 
      document.getElementById('myForm').style.display = 'none'; 
      document.getElementById('output').innerHTML = status; 
     } 
    </script> 

    <style> 
    input { display:block; margin: 20px; } 
    </style> 

這是我的 「部署爲Web應用程序」 的配置:here

我打開每一個建議,沒有必要使用谷歌腳本如果有更可靠的道路

+1

從腳本編輯器運行doGet以獲取授權請求對話框 – 2014-09-23 09:25:20

+0

已經嘗試過,我遵循的指南解釋此步驟 – gagna 2014-09-23 09:28:54

+0

允許第三方雲端硬盤應用程序設置是否在您的域中啓用? – Greg 2014-09-25 14:25:48

回答

0

我試過了這段代碼,在打開其中一條評論中提到的Google驅動器應用程序@Greg後,它對我有用。

對於此設置在管理控制檯中去: 谷歌Apps>雲端硬盤>常規設置>,然後檢查「允許用戶安裝谷歌雲端硬盤應用」

這段代碼的文件將

而且盒子存儲在當前用戶的驅動器中,而不是在管理員的驅動器中。要解決它,你必須爲以下內容:

  • 在管理員的驅動
  • 將文件夾複製ID
  • 在Appscript使用方法 「變種文件夾= DriveApp.getFolderById(」文件夾中創建文件ID');' - 你將不需要的代碼創建文件夾,因爲它已經在這裏
  • 文件夾做需要與用戶共享
  • 用戶將需要請求權限訪問

希望幫助。

0

看看這個鏈接,它使用谷歌選擇器中的Apps腳本環境 - 因此提供了進度條ECT一個漂亮的漂亮的用戶界面..

主要警告是選擇特定的上傳文件夾需要多個上傳啓用

https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs

你需要改變它稍微加上傳查看詳情如下。

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.'); 
    } 
    } 

我的具體使用情況是一個單一的上傳,所以我不得不寫一些額外的代碼將文件移動到指定的文件夾 - 它很容易壽:)

當測試作爲Web應用程序確保爲您的「最新代碼」使用測試Web應用程序。 - 在下發現 - >部署爲WEB應用程序...

當您準備好共享時,您將不得不創建新版本併發布該版本!這讓我意識不到,如果你不熟悉它:D - 找到FILE - >管理版本...並保存新版本然後PUBLISH - >部署爲WEB應用程序...並選擇下拉列表中的新版本。

相關問題