1

Currently I'm using an example to create an upload function for my webpage on Google Apps Script. This is the code:

Code.gs

function doGet(e) {
 return HtmlService.createHtmlOutputFromFile('form.html');
}

function uploadFiles(form) {

 try {

 var dropbox = "Test Files";
 var folder, folders = DriveApp.getFoldersByName(dropbox);

 if (folders.hasNext()) {
  folder = folders.next();
 } else {
  folder = DriveApp.createFolder(dropbox);
 }

 var blob = form.myFile;    
 var file = folder.createFile(blob);    
 file.setDescription("Uploaded by " + form.myName);

 return "File uploaded successfully " + file.getUrl();

 } catch (error) {

 return error.toString();
 }

}

form.html

<form id="myForm">
<input type="text" name="myName" placeholder="Your name..">
<input type="file" name="myFile">
<input type="submit" value="Upload File" 
       onclick="this.value='Uploading..';
                google.script.run.withSuccessHandler(fileUploaded)
                .uploadFiles(this.parentNode);
                return false;">
</form>

<div id="output"></div>

<script>
    function fileUploaded(status) {
        document.getElementById('myForm').style.display = 'none';
        document.getElementById('output').innerHTML = status;
    }
</script>

<style>
 input { display:block; margin: 20px; }
</style>

This code works fine by itself but when I try and implement it on my webpage with the current existing code: https://jsfiddle.net/05nmqy63/

It won't work like shown in the example. The example uploads a file into a folder in my Google Docs but when put into my code the page changes but it doesn't upload anything nor does it say the file has been submitted.

How do I fix this? Or is there an easier way to implement an upload button? (I want the submit order button to be able to function as the upload button)

Kali
  • 93
  • 1
  • 8
  • When it doesn't work, have you looked at the javascript console to see if any errors are being reported? – Stephen P Dec 07 '15 at 20:44
  • @StephenP I don't think google apps script has a javascript console :/ – Kali Dec 07 '15 at 20:50
  • Right-click in Chrome, 'Inspect`, click 'Console' tab on the panel that shows up. – serraosays Dec 07 '15 at 21:00
  • this is what is being reported: Uncaught InvalidArgumentError: Failed due to illegal value in property: 0 how do I fix this? – Kali Dec 07 '15 at 21:05
  • Possible duplicate of [google.script.run not working: Uncaught InvalidArgumentError: Failed due to illegal value in property: 0](http://stackoverflow.com/questions/27680509/google-script-run-not-working-uncaught-invalidargumenterror-failed-due-to-ille) – Stephen P Dec 07 '15 at 22:09

1 Answers1

0

Figured out the problem to my question after finding out what was wrong. The error I received was this: Uncaught InvalidArgumentError: Failed due to illegal value in property: 0

This error was solved by another person on this forum: google.script.run not working: Uncaught InvalidArgumentError: Failed due to illegal value in property: 0

Community
  • 1
  • 1
Kali
  • 93
  • 1
  • 8