0

Basic HTML form for with file objects to save in Google Drive. Using google Apps Script and deployed as a web app, the HTML displays as expected and returns the uploaded file URL.

However, the file (pdf) contain the pages as the original file but appears to have no visible content.

The application worked with the code below for some time, but now saves blank documents to google drive.

Some assistance would be greatly appricated.

function doGet() {
  return HtmlService
      .createTemplateFromFile('html')
      .evaluate();
}

function processForm(formObject) {
  try{
    // get form object by formObject names
    
    var blob = formObject.file
    var name = formObject.fname;
    
    // Get Folder and open in Drive
    
    var folderId = "................"
    var folder = DriveApp.getFolderById(folderId);
    
    // create file and save to folder
    
    var driveFile = folder.createFile(blob);
    var url = driveFile.getUrl();
    
    return url;
  }catch(e){
    return arguments.callee.name+"<\br>"+e;
  }
}

The html template

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    
    <script>
      function preventFormSubmit() {
        var forms = document.querySelectorAll('form');
        for (var i = 0; i < forms.length; i++) {
          forms[i].addEventListener('submit', function(event) {
            event.preventDefault();
          });
        }
      }
      // execute load prvention 
      window.addEventListener('load', preventFormSubmit);
      // ------------
    
      function onFormSubmit(formData){
        var div = document.getElementById('output');
        div.innerHTML = "PLEASE WAIT! .....";
        google.script.run.withSuccessHandler(successResponse).withFailureHandler(failureResponse).processForm(formData); // returns message
      }
      
      function successResponse(response) {
        var div = document.getElementById('output');
        div.innerHTML = response;
        document.getElementById('file').value = "";
      }
      
      function failureResponse(response) {
        var div = document.getElementById('output');
        div.innerHTML = response;
        document.getElementById('file').value = "";
      }
      </script>
  </head>
  
  <body>
    <form id="form" onsubmit="onFormSubmit(this)">
    
    <label for="email">Name</label>
    <input type='text' name='name' id="name" required="required"/>
    
    <label for="File">Email</label>
    <input type='file' name='file' id="file" required="required"/>
    
    <button type="submit" class="action">Submit</button>
    </form>
    <div id="output" ></div>
  </body>
</html>
Gordon K
  • 51
  • 1
  • 2
  • I thought that this thread might be useful for your situation. https://stackoverflow.com/q/60742695/7108653 So if you enable V8 runtime, how about disabling and testing it again? Or, when you want to enable V8, how about sending the data as the byte array and base64 data? – Tanaike Nov 05 '20 at 04:54
  • Wow, that fixed it. Thank you. – Gordon K Nov 05 '20 at 05:28
  • Thank you for replying. I'm glad your issue was resolved. – Tanaike Nov 05 '20 at 05:35

0 Answers0