title: Create folders for uploaded files on Google Apps Script
body: <p>As of right now, the code is uploading the files into the "something" folder. </p>
  
  <p>I'm trying to make it so that each time I upload a set of files, they will all go into their own separate folder inside of the main upload folder. </p>
  
  <p>I'm also trying to set up a return to show confirmation for a completed upload, but the files just simply get uploaded and nothing happens afterwards. Thanks</p>
  
  <p>form.html</p>
  
  <pre><code>&lt;body&gt;
    &lt;div id="formcontainer"&gt;
  
      &lt;label for="myForm"&gt;Project Database Attachment Uploader:&lt;/label&gt;
  
      &lt;br&gt;&lt;br&gt;
  
  
      &lt;form id="myForm"&gt; 
        &lt;label for="myForm"&gt;Project Details:&lt;/label&gt;
        &lt;div&gt;
          &lt;input type="text" name="zone" placeholder="Zone:"&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;input type="text" name="building" placeholder="Building(s):"&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;input type="text" name="propertyAddress" placeholder="Property Address:"&gt;
        &lt;/div&gt;
        &lt;div&gt;
  
        &lt;label for="fileText"&gt;Project Description:&lt;/label&gt;
  
            &lt;TEXTAREA name="projectDescription" 
            placeholder="Describe your attachment(s) here:"
            style ="width:400px; height:200px;"
            &gt;&lt;/TEXTAREA&gt;
  
  
        &lt;/div&gt; 
        &lt;br&gt;
  
  
        &lt;label for="attachType"&gt;Choose Attachment Type:&lt;/label&gt;
        &lt;br&gt;
        &lt;select name="attachType"&gt;
          &lt;option value="Pictures Only"&gt;Picture(s)&lt;/option&gt;
          &lt;option value="Proposals Only"&gt;Proposal(s)&lt;/option&gt;
          &lt;option value="Pictures &amp; Proposals"&gt;All&lt;/option&gt;
        &lt;/select&gt;
        &lt;br&gt;
  
        &lt;label for="myFile"&gt;Upload Attachment(s):&lt;/label&gt;
        &lt;br&gt;
  
  
        &lt;input type="file" name="filename" id="myFile" multiple&gt;
  
        &lt;input type="button" value="Submit" onclick="iteratorFileUpload()"&gt;
  
  
      &lt;/form&gt;
    &lt;/div&gt;
  
    &lt;div id="output"&gt;&lt;/div&gt;
  &lt;div id="progressbar"&gt;
      &lt;div class="progress-label"&gt;&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
  var numUploads = {};
  numUploads.done = 0;
  numUploads.total = 0;
  
  // Upload the files into a folder in drive
  // This is set to send them all to one folder (specificed in the .gs file)
  function iteratorFileUpload() {
      var allFiles = document.getElementById('myFile').files;
  
      if (allFiles.length == 0) {
          alert('No file selected!');
      } else {
          //Show Progress Bar
  
          numUploads.total = allFiles.length;
          $('#progressbar').progressbar({
          value : false
          });//.append("&lt;div class='caption'&gt;37%&lt;/div&gt;");
          $(".progress-label").html('Preparing files for upload');
          // Send each file at a time
          for (var i = 0; i &lt; allFiles.length; i++) {
              console.log(i);
              sendFileToDrive(allFiles[i]);
          }
      }
  }
  
  function sendFileToDrive(file) {
      var reader = new FileReader();
      reader.onload = function (e) {
          var content = reader.result;
          console.log('Sending ' + file.name);
          var currFolder = 'Something';
          google.script.run.withSuccessHandler(updateProgressbar).uploadFileToDrive(content, file.name, currFolder);
      }
      reader.readAsDataURL(file);
  }
  
  function updateProgressbar( idUpdate ){
     console.log('Received: ' + idUpdate);
     numUploads.done++;
     var porc = Math.ceil((numUploads.done / numUploads.total)*100);
     $("#progressbar").progressbar({value: porc });
     $(".progress-label").text(numUploads.done +'/'+ numUploads.total);
     if( numUploads.done == numUploads.total ){
        //uploadsFinished();
        numUploads.done = 0;
     };
  }
  &lt;/script&gt;
  
    &lt;script&gt;
      function fileUploaded(status) {
        document.getElementById('myForm').style.display = 'none';
        document.getElementById('output').innerHTML = status;
      }
  
    &lt;/script&gt;
  
    &lt;style&gt;
      body {
        max-width: 400px;
        padding: 20px;
        margin: auto;
      }
      input {
        display: inline-block;
        width: 100%;
        padding: 5px 0px 5px 5px;
        margin-bottom: 10px;
        -webkit-box-sizing: border-box;
        ‌​ -moz-box-sizing: border-box;
        box-sizing: border-box;
      }
      select {
        margin: 5px 0px 15px 0px;
      }
      input[type="submit"] {
        width: auto !important;
        display: block !important;
      }
      input[type="file"] {
        padding: 5px 0px 15px 0px !important;
      }
  #progressbar{
      width: 100%;
      text-align: center;
      overflow: hidden;
      position: relative;
      vertical-align: middle;
  
  }
  .progress-label {
        float: left;
  margin-top: 5px;
        font-weight: bold;
        text-shadow: 1px 1px 0 #fff;
            width: 100%;
      height: 100%;
      position: absolute;
      vertical-align: middle;
      }
    &lt;/style&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>code.gs</p>
  
  <pre><code>function doGet() {
    return HtmlService.createHtmlOutputFromFile('form')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  }
  
  function uploadFileToDrive(base64Data, fileName) {
    try{
      var splitBase = base64Data.split(','),
          type = splitBase[0].split(';')[0].replace('data:','');
  
      var byteCharacters = Utilities.base64Decode(splitBase[1]);
      var ss = Utilities.newBlob(byteCharacters, type);
      ss.setName(fileName);
  
      var dropbox = "Something"; // Folder Name
      var folder, folders = DriveApp.getFoldersByName(dropbox);
  
      if (folders.hasNext()) {
        folder = folders.next();
      } else {
        folder = DriveApp.createFolder(dropbox);
      }
      var file = folder.createFile(ss);
  
      return file.getName();
    }catch(e){
      return 'Error: ' + e.toString();
    }
  }
  </code></pre>