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>