title: Google Script - Multi File Upload - How to Upload Files to New Sub-folder
body: <p>I am trying to modify the below to code so the all files in the <code>var fileBlob = e.parameter['file'+i];</code> are uploaded into the new sub-folder that is created. </p>
  
  <p>After submitting the upload, a new folder is created for each file uploaded and each file is uploaded to each folder. </p>
  
  <p>How can I get the doPost to submit the upload files to the new sub-folder only. So if I upload 20 files, 20 files are added/uploaded to the one sub-folder only.</p>
  
  <p><strong>Multi File Upload Ui Form</strong></p>
  
  <p><img src="https://i.stack.imgur.com/NUqW8.png" alt="Upload UI"></p>
  
  <p><strong>Google Drive Results</strong></p>
  
  <p><img src="https://i.stack.imgur.com/KAXV2.png" alt="G-Drive Folders Created"></p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>function doPost(e) {
    var foldername = e.parameter.folderName;
    Logger.log('foldername = '+foldername);
    var numFiles = Number(e.parameter.hidden);
    Logger.log('numFiles = '+numFiles);
    for (var i = 1; i&lt;=numFiles; i++){
      Logger.log(i);
      var fileBlob = e.parameter['file'+i];
      Logger.log(fileBlob);
      var newFolder = DocsList.getFolderById("0Bw8NytPhOo00b0xIVm41LWlZRlk").createFolder(foldername);
      newFolder.getUrl();
      Logger.log(newFolder.getUrl());
      var newFile = DocsList.createFile(fileBlob);
      newFile.addToFolder(newFolder);
  
    }
  </code></pre>
  
  <p><strong>Full Code</strong> <a href="https://stackoverflow.com/questions/22277521/gas-e-parameter-undefined-uploadwidget-wont-setname&quot;">here</a> (Created by Serge insas)</p>