0

I am trying to write a code to upload files into my google drive folder using a html site using google apps script. Below is my code

function doGet() {
  var html = HtmlService.createHtmlOutputFromFile('index');
  return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

function uploadFiles(data){   
  var file = data.myFile;
  var folder = DriveApp.getFolderById('1iQLoUag-jZluW_vBakuHcL6LBnnGyzgS');
  var createFile = folder.createFile(file);
  return createFile.getUrl();
}
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <title>Upload Files</title>
  </head>
  <body>
    <h1>File Uploader</h1>
    <form>
        <input type="file" name="myFile" mulitple>
        <br>
        <br>
        <input type="button" id="submitBtn" value="Upload Files">
        <label id="resp"></label>
    </form>
    <script>
      document.getElementById('submitBtn').addEventListener('click',
        function(e){
          google.script.run.withSuccessHandler(onSuccess).uploadFiles(this.parentNode)
        })
        
        function onSuccess(data){
          document.getElementById('resp').innerHTML = "File Uploaded to the path " +data;
        }
       
    </script>
  </body>
</html>

But it never uploads a file. Inspecting the site shows me this error, Error in the console when I clock upload button:

Rubén
  • 34,714
  • 9
  • 70
  • 166
GASNerd
  • 1
  • 1
  • 1. Catch the error with `withFailureHandler()` 2. Serverlogs: view> executions>timestamps when you click the upload. – TheMaster Aug 31 '20 at 21:18
  • How big is your file? Big enough to make the script time out like [here](https://stackoverflow.com/questions/37041045/using-google-drive-api-to-upload-large-files)? Cinsider an [alternative approach](https://stackoverflow.com/questions/60827372/blank-pdf-files-when-using-google-api/60828884#60828884). – ziganotschka Sep 01 '20 at 08:48
  • 1
    @ziganotschka Thank you so much. I used the code in the alternative approach and it works. i don't know why the previous one didn't work. And by the way, mine is just a 100kB xlsx file I wanted to upload. – GASNerd Sep 01 '20 at 16:31

0 Answers0