0

I am using the Google Drive Picker API to facilitate file upload from within a Google Spreadsheet. The problem the user is reporting is that not all folders in a sub folder are visible or searchable.

The sub folder in question has a large amount of sub folders itself. (About a 1000+) Does anyone know if Drive Picker has some kind of a limitation around the number of folders it can display?

As requested my code below:

function showPicker() {
  var html = HtmlService.createHtmlOutputFromFile('0.2 Picker.html')
      .setWidth(600)
      .setHeight(425)
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi().showModalDialog(html, 'Select Invoice(s)');
}

function getOAuthToken() {
  DriveApp.getRootFolder();
  return ScriptApp.getOAuthToken();
}

//Picker.html

    <!DOCTYPE html>
    <html>
    <head>
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
    <script type="text/javascript">
    var DIALOG_DIMENSIONS = {
    width: 600,
    height: 425
    };

    var pickerApiLoaded = false;

    function onApiLoad() {
    gapi.load('picker', {
    'callback': function() {
    pickerApiLoaded = true;
    }
    });
    google.script.run.withSuccessHandler(createPicker)
    .withFailureHandler(showError).getOAuthToken();
    }

    function createPicker(token) {

    if (pickerApiLoaded && token) {

    var docsView = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
    .setIncludeFolders(true)
    .setMimeTypes('application/vnd.google-apps.spreadsheet')
    .setParent("ID_OF_FOLDER_GOES_HERE");


    var picker = new google.picker.PickerBuilder()
    .addView(docsView)
    .enableFeature(google.picker.Feature.NAV_HIDDEN)
    .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
    .enableFeature(google.picker.Feature.SUPPORT_DRIVES)
    .hideTitleBar()
    .setSize(DIALOG_DIMENSIONS.width - 2, DIALOG_DIMENSIONS.height - 2)
    .setOAuthToken(token)
    .setCallback(pickerCallback)
    .setOrigin('https://docs.google.com')
    .build();

    picker.setVisible(true);

    } else {
    showError('Unable to load the file picker.');
    }
    }

    /**
    * A callback function that extracts the chosen document's metadata from the
    * response object. For details on the response object, see
    * https://developers.google.com/picker/docs/result
    *
    * @param {object} data The response object.
    */
    function pickerCallback(data) {

    //Get the user's response action
    var action = data[google.picker.Response.ACTION];

    //Test if users selected "Picked", if true, do the following:
    if (action == google.picker.Action.PICKED) {

    //Get documents uploaded by google picker 
    var files = data[google.picker.Response.DOCUMENTS];

    //Create an array to house ID's of uploaded documents
    var arrayOfIds = [];

    //For the number of elements in the files array do the following
    for (var i = 0; i < files.length; i++) {

    //Get the id of the current file
    var id = files[i][google.picker.Document.ID]

    //Push id of current file into arrayOfIds
    arrayOfIds.push(id)

    }//END OF FOR LOOP I

    //Call getInvoiceData passing in array of IDs            
    google.script.run.getInvoiceData(arrayOfIds);

    //Close the upload box
    google.script.host.close()

    }//END OF IF STATEMENT

    //Check action does not "Picked", check if action is "Cancel"
    else if (action == google.picker.Action.CANCEL) {

    google.script.host.close();

    }//END OF ELSE IF
    }//END OF FUNCTION

    function showError(message) {
    document.getElementById('result').innerHTML = 'Error: ' + message;
    }

</script>
</head>

<body>
<div>
<p id='result'></p>
</div>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
</body>
</html>
New_2_Code
  • 330
  • 2
  • 18
  • Could you share the cod with which you're setting up the Picker? including the scopes you're giving it. if you also look at [this answer](https://stackoverflow.com/a/10313416/11581830) you can see that Drive has a limit of 1,000 requests in 100 seconds, if the picker is trying to get every file in the folder and each has a bunch of subfolders you could be hitting the quota. – AMolina Aug 23 '19 at 09:47
  • Hi, i've added my code to my question. I am also reading through the answer you posted. – New_2_Code Aug 23 '19 at 09:55
  • 1
    Looking at the code it seems you haven't added the scopes for the Picker, I suggest you take a look at [this example](https://developers.google.com/picker/docs/#hiworld) to see if you're missing anything in the set-up. That entire page has a lot of information on working with Picker. – AMolina Aug 23 '19 at 10:17
  • Thanks a mil, going to read through it now. – New_2_Code Aug 23 '19 at 10:22
  • 1
    No problem, feel free to update the question if anything new comes up. – AMolina Aug 23 '19 at 10:37

0 Answers0