title: HTML form file upload to Google Drive and save URL to google sheet
body: <p>I'm new to the world of google scripting, and have found some great tutorials on how to either:
  i Upload a file to Google Drive with HTML form
  ii Append new rows to a google sheet.</p>
  
  <p>Essentially I am trying to to write a basic HTML form that collects a few text fields and file attachment, where the file attachment is uploaded to my google drive and the URL along with the other form text fields are appended a Google Sheet.</p>
  
  <p>Here is the HTML form I am working with (based on a tutorial I found):</p>
  
  <pre><code>&lt;!-- Include the Google CSS package --&gt;
  &lt;link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css"&gt;
  
  &lt;!-- You can also include your own CSS styles --&gt;
  &lt;style&gt;
    form { margin: 40px auto; }
    input { display:inline-block; margin: 20px; }
  &lt;/style&gt;
  
  &lt;script&gt;
  
    // The function will be called after the form is submitted
    function uploadFile() {
      document.getElementById('uploadFile').value = "Uploading File..";
      google.script.run
         .withSuccessHandler(fileUploaded)
         .uploadFiles(document.getElementById("labnol"));
      return false;
    }
  
    // This function will be called after the Google Script has executed
    function fileUploaded(status) {
      document.getElementById('labnol').style.display = 'none';
      document.getElementById('output').innerHTML = status;
    }
  
  &lt;/script&gt;
  
  &lt;!-- This is the HTML form --&gt;
  &lt;form id="labnol"&gt;
  
    &lt;!-- Text input fields --&gt;
    &lt;input type="text" id="nameField" name="myName" placeholder="Your name.."&gt;
    &lt;input type="email" id="emailField" name="myEmail" placeholder="Your email.."&gt;
  
    &lt;!-- File input filed --&gt;
    &lt;input type="file" name="myFile"&gt;
  
    &lt;!-- The submit button. It calls the server side function uploadfiles() on click --&gt;
    &lt;input type="submit" id="uploadFile" value="Upload File"
           onclick="this.value='Uploading..';uploadFile();"&gt;
  
  &lt;/form&gt;
  
  &lt;!-- Here the results of the form submission will be displayed --&gt;
  &lt;div id="output"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>And here is the google script (again, based on a useful tutorial on a blog)</p>
  
  <pre><code>/* The script is deployed as a web app and renders the form */
  function doGet(e) {
    return HtmlService.createHtmlOutputFromFile('form.html')
              .setSandboxMode(HtmlService.SandboxMode.NATIVE);
    // This is important as file upload fail in IFRAME Sandbox mode.
  }
  
  /* This function will process the submitted form */
  function uploadFiles(form) {
  
    try {
  
      /* Name of the Drive folder where the files should be saved */
      var dropbox = "Test Form Submissions";
      var folder, folders = DriveApp.getFoldersByName(dropbox);
  
      /* Find the folder, create if the folder does not exist */
      if (folders.hasNext()) {
        folder = folders.next();
      } else {
        folder = DriveApp.createFolder(dropbox);
      } 
  
      /* Get the file uploaded though the form as a blob */
      var blob = form.myFile;
      var file = folder.createFile(blob);
  
      //Allocate variables for submissions in sheet
      var namerecord = form.myName;
      var emailrecord = form.myEmail;
  
      /* Set the file description as the name of the uploader */
      file.setDescription("Uploaded by " + form.myName);
  
      /* Return the download URL of the file once its on Google Drive */
      return "File uploaded successfully " + file.getUrl();
  
      var uploadURL = file.getUrl();
  
  
    //
  
    } catch (error) {
  
      /* If there's an error, show the error message */
      return error.toString();
    }
  
          //Open spreadsheet based on URL
    var googsheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/17fuu1vUuxgCgs1TpSGpWDNxMHX3AEFscmjX156HQ5_U/edit?usp=sharing');
    Logger.log(googsheet.getName());
  
    var sheet = googsheet.getSheets()[0];
    sheet.appendRow(["James", "jim", "abc"]);
  
  
  
  }
  </code></pre>
  
  <p>My intuition was simply to slip some lines of code in to add the form data to the specified sheet but it's not working and I must be doing something wrong :S</p>
  
  <p>Any advice would be greatly appreciated to an ignorant Business Analyst new to web programming :/</p>
  
  <p>Thanks</p>