user3140792
user3140792

Reputation: 71

cannot get folder created by another apps script on google drive

Using the following apps script function i can successfully create folders in google drive:

function uploadFileToGoogleDrive(data, file, name, email) {  

    var parentFolderId = "FOLDER_ID";
    var parentFolder = DriveApp.getFolderById(parentFolderId);
    var subfolder;

        try {
    subfolder = parentFolder.getFoldersByName([name, email].join(" ")).next();
    }
    catch(e) {
    subfolder = parentFolder.createFolder([name, email].join(" "));
    }
      var contentType = data.substring(5,data.indexOf(';')),
        bytes = Utilities.base64Decode(data.substr(data.indexOf('base64,')+7)),
        blob = Utilities.newBlob(bytes, contentType, file),
        file = subfolder.createFile(blob);

          file = subfolder.createFile(file, data);
   Logger.log(subfolder);  
      return "OK";
}

i want to access the folder using the following script:

function downloadFile(e) {  
  var parentFolderId = "FOLDER_ID";
  var parentFolder = DriveApp.getFolderById(parentFolderId);

 var subfolderId;
 var subfolders = parentFolder.getFoldersByName([name, email].join(" "));

while (subfolders.hasNext()) {
  var folder = subfolders.next();
  Logger.log(folder.getId());
}
}

appsscript.json for uploadFileToGoogleDrive:

{
  "timeZone": "Europe/Bucharest",
  "dependencies": {
  },
  "webapp": {
    "access": "ANYONE_ANONYMOUS",
    "executeAs": "USER_DEPLOYING"
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

appsscript.json for downloadFile :

{
  "timeZone": "Europe/Bucharest",
  "dependencies": {
  },
  "webapp": {
    "access": "ANYONE_ANONYMOUS",
    "executeAs": "USER_DEPLOYING"
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.readonly"],
  "runtimeVersion": "V8"
}

The script can access ONLY the folders Created with google drive Web! But cannot get the folders created with other apps script.

Note that the two functions (upload and download) are in separate google apps scripts.

Upvotes: 1

Views: 122

Answers (1)

user3140792
user3140792

Reputation: 71

Thanks @alberto vielma, As @TheMaster suggested, my problem was in name and email, a hidden "space" was by mistake in their string values which prevent them to match the folder name. Thanks all..

Upvotes: 0

Related Questions