如何在Drive to Google脚本中创建文件夹内的文件夹?

时间:2016-03-21 12:25:49

标签: jquery html forms google-apps-script google-drive-api

我使用现有的文件夹ID上传文件,但是每当用户按下提交按钮时,我都希望按用户名创建文件夹。 请查看我的form。帮我解决这个问题。

JS:



var dropBoxId = "123454567567"; // Drive ID of 'dropbox' folder
var logSheetId = "xoxoxoxooxoxox"; // Drive ID of log spreadsheet

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

function uploadFiles(formObject) {
  try {
    // Create a file in Drive from the one provided in the form
    var folder = DriveApp.getFolderById(dropBoxId);
    var person = createFolder(ajith);
    var blob1 = formObject.myFile1;  
    var blob2 = formObject.myFile2;  
    var blob3 = formObject.myFile3;  
    var file1 = person.createFile(blob1);    
    var file2 = person.createFile(blob2);    
    var file3 = person.createFile(blob3);    
    file.setDescription("Uploaded by " + formObject.myName);

    // Open the log and record the new file name, URL and name from form
    var ss = SpreadsheetApp.openById(logSheetId);
    var sheet = ss.getSheets()[0];
    sheet.appendRow([formObject.myName, formObject.myEmail, formObject.myCert, formObject.myExp, formObject.mySkills, formObject.myFees, formObject.myLoc, formObject.myTravel, file1.getName(),file2.getName(),file3.getName(), file1.getUrl(),file2.getUrl(),file3.getUrl(), file.getDateCreated() ]);

    // Return the new file Drive URL so it can be put in the web app output
    return file.getUrl();
  } catch (error) {
    return error.toString();
  }
}

HTML:
<form>
<h2 class="text-center title">Application Form</h2>
<div class="col-sm-6" id="myForm">
  <div><label>Name:</label><input type="text" name="myName" placeholder="Your full name..." required/></div>
  <div><label>Mobile Number:</label><input type="number" name="myNum" placeholder="Mobile number..." required/></div>
  <div><label>Email:</label><input type="email" name="myEmail" placeholder="Email ID..." required/></div>
  <div><label>Certificate:</label><input type="text" name="myCert" placeholder="Certificate Name..." required/></div>
  <div><label>Experience:</label><input type="number" name="myExp" placeholder="Experience in years..." required/></div>
  <div><label>Skills:</label><input type="text" name="mySkills" placeholder="Skills(seperate by comma).." required/></div>
</div>
<div class="col-sm-6" id="myForm">
  <div><label>Fees:</label><input type="text" name="myFees" placeholder="Fees..." required/></div>
  <div><label>Locality:</label><input type="text" name="myLoc" placeholder="Locality..." required/></div>
  <div><label>Willingness to travel:</label><select><option>Yes</option><option>No</option></select></div>
  <div><label>Attach your latest Photo 1</label><input name="myFile1" type="file" required/></div>
  <div><label>Attach your latest Photo 2</label><input name="myFile2" type="file" required/></div>
  <div><label>Attach your latest Photo 3</label><input name="myFile3" type="file" required/></div>
</div>
<input type="button" class="btn btn-success" value="Submit"
      onclick="google.script.run
          .withSuccessHandler(updateUrl)
          .withFailureHandler(onFailure)
          .uploadFiles(this.parentNode)" />
</form>

<div id="output"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

尝试这样的事情

 var name ="Myfoldernanme";
 var newfolder = folder.createFolder(name);