0

I have a form action post inside an html that I call the following appscript function, to upload a file to google drive

function doPost(e) {
  var data = Utilities.base64Decode(e.parameters.data);
  var blob = Utilities.newBlob(data, e.parameters.mimetype, e.parameters.filename);
  var folder = DriveApp.getFolderById("-----"); //Get folder of destiny for file (final user need access before execution)
  var newFile = folder.createFile(blob);                                   //Create new file (property of final user)
  return?!!!?!?!?!!?!?!?! //HERE IS MY PROBLEM
}

Is there any way that when I hit submit it doesn't take me to the google app script page indicating a code? I mean it stays inside my html without reloading the page

I attach my form just in case

<form action="https://script.google.com/macros/s/----------/exec" id="form" method="post">
<div id="data"></div>
<input name="file" id="uploadfile" type="file">
<input id="submit" type="submit">
</form>
  • @idfurw Give me this error : Failed to load resource: the server responded with a status of 500 () – Alejandro Capra Apr 20 '22 at 03:35
  • I'm worried that your HTML form might not be able to upload the file to Web Apps of `doPost`. Because when your HTML form is submitted, the file information is not included. How about this? And, can I ask you where your HTML is in? Is your HTML included in the Google Apps Script project? Or, is your HTML put on another site outside of the Google Apps Script project? – Tanaike Apr 20 '22 at 04:43
  • @Tanaike mi code is outside – Alejandro Capra Apr 20 '22 at 16:21
  • Thank you for replying. I understood `mi code is outside`. I'm worried that your HTML form might not be able to upload the file to Web Apps of `doPost`. Because when your HTML form is submitted, the file information is not included. How about this? – Tanaike Apr 21 '22 at 00:32
  • @Tanaike i found this solution https://stackoverflow.com/questions/63374794/upload-file-to-my-google-drive-with-google-apps-script-no-form-in-google – Alejandro Capra Apr 22 '22 at 19:30

1 Answers1

0
<form>
  <div id="data"></div>
  <input name="file" id="uploadfile" type="file">
  <input value="Submit" type="button" onClick="processForm(this.parentNode);" />
</form>
<script>
  function processForm(form) { 
    //do nothing or whatever you wish
  }
</script>
Cooper
  • 59,616
  • 6
  • 23
  • 54