0

I don´t know if there is a way on making this work, but I want to make a form with input type=file.
But when I submit the form it won't work cause of the input type=file and cause of my access permission is set to me only in the Google Apps Script.

Well the code goes like this, I'm just showing the base code which I'm having trouble with. Whenever I remove the line with the input file it will submit the form and add in a spreadsheet the value I've input in the first name text box. And I've notice that it also works when I leave the input file line, when I change the permissions in my script, when I publish the code as a web app, and in the "Who has access to the app" put "Anyone, even anonymous", the thing is that I don't want that anyone could access the webapp. I'm just thinking on rewritting the gs code to check the user accessing the web app, but I'm not sure if this would be safe.

GS Code:

function doGet() { 
var template = HtmlService.createTemplateFromFile('HtmlName'); 
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);}

function processForm(formObject) {
var formBlob = formObject.myFile;
var driveFile = DriveApp.createFile(formBlob);

var firstName = formObject.firstName;

DriveApp.getFolderById("anyID").addFile(driveFile);   

ss.appendRow([formObject.firstName,
                           ]);}

Html File

<!DOCTYPE html>
<html>
<body>
<form class="w3-container" id="myForm" onsubmit="handleFormSubmit(this); ">
     
  <p>
  <input class="w3-input" name="myFile" type="file">
  <input class="w3-input" type="text" name="firstName">      
  <p>     
  <input class="w3-button" type="submit" value="Submit">
           
  </form>
  </body>
  
  <script>
  // Prevent forms from submitting.
  function preventFormSubmit() {
  var forms = document.querySelectorAll('form');
  for (var i = 0; i < forms.length; i++) {
  forms[i].addEventListener('submit', function(event) {
  event.preventDefault();
  });    }      }
  window.addEventListener('load', preventFormSubmit);

  function handleFormSubmit(formObject) {
  google.script.run.withSuccessHandler(updateUrl).processForm(formObject);
  }     
  </script>
  </html>
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • 1
    `input type="file"` is used for uploading files from your computer. Is that what your triying to do. Your explanation is not clear. Please provide the code that you have tried. – Cooper May 06 '20 at 19:08
  • 1
    Welcome to StackOverFlow please take this opportunity to take the [tour] and learn how to [ask], [format code](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks), [mcve] and [Tag Info](https://stackoverflow.com/tags/google-apps-script/info) – Cooper May 06 '20 at 19:08
  • 3
    Does this answer your question? [Moving google apps script to v8 file upload stopped working from sidebar](https://stackoverflow.com/questions/60742695/moving-google-apps-script-to-v8-file-upload-stopped-working-from-sidebar) – TheMaster May 06 '20 at 19:13

1 Answers1

0

There is a known issue regarding the use of <input type="file" /> on Google Apps Script HTML Service when using the new default runtime (Chrome V8)1. As your code isn't using features not supported by the old runtime, try to disable the new runtime (click on Run > Disable new Google Apps Script runtime powered by Chrome V8).

If disabling the new runtime doesn't work try using FileReader.

NOTES:

  1. See Tanaike's answer to Moving google apps script to v8 file upload stopped working from sidebar
Rubén
  • 34,714
  • 9
  • 70
  • 166