0

Attempting to upload a file to google drive from Local using a custom HTML dialog.

On clicking upload in the dialog it waits a few seconds and then shows an error:

"failed UploadWe're sorry, a server error occurred. Please wait a bit and try again."

It is just not running the server side function. I have tried changing the server side function just to return anything and it is just not working so I don't think it's a problem with the server side function itself. Something about the communication between client and server.

Do you have any idea why this is not working?

// Use this code for Google Docs, Slides, Forms, or Sheets.
function onOpen() {
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
    .createMenu('Dialog')
    .addItem('Upload', 'uploadDialog')
    .addToUi();
}

function uploadDialog() {
  var html = HtmlService.createHtmlOutputFromFile('Index');
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
    .showModalDialog(html, 'Upload File Here');
}


function uploadFile(frmdata) {
  var fileBlob = frmdata.fileToUpload
  if (fileBlob.getName() != "") {
    var fldrSssn = DriveApp.getFolderById("1nFl9S3pgR9IXSKVuKh9sUGOKi5adEHR1");
    var picFile = fldrSssn.createFile(fileBlob);
  }

}
<!DOCTYPE html>
<html>

<head>
  <base target="_top">
</head>

<body>
  <form id="fileform" onsubmit="event.preventDefault()">
    <input type="file" id="file" name="fileToUpload">
    <input type="Button" value="Upload" onclick="uploadthis(this.parentNode)">
  </form>
</body>

<script>
  function uploadthis(frmData) {
    google.script.run
      .withSuccessHandler(closeDialog)
      .withFailureHandler(alertFailure)
      .uploadFile(frmData);

  }

  function closeDialog() {
    google.script.host.close()
  }

  function alertFailure(error) {
    google.script.host.close()
    alert("failed Upload" + error.message)
  }
</script>

</html>
  • I thought that [this thread](https://stackoverflow.com/q/60742695/7108653) might be the answer for your question. How about this? – Tanaike Mar 01 '21 at 01:29

1 Answers1

0

This behavior is a known issue with V8 runtime. Here is the link: https://issuetracker.google.com/150675170. You can click on the star icon to indicate you are affected by it too.

Aerials
  • 4,231
  • 1
  • 16
  • 20