0

As title, I am currently working on an uploading page which enables users to upload the files(jpg and Doc) to the folder on Google Drive. However, the problems seem to be that although the files are uploaded successfully, I am not able to open them, and the size of the files is bigger in comparison to the original one. Below is what I currently have, please let me know if this can get any further.

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

function uploadFiles(form) {  
try {
  var dropbox = "1 作文上傳";
  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("上傳者: " + form.Name + " 電話: "+ form.Phone + " 信箱: " + form.Email);
 
  return "<h2>雲端上傳系統</h2><input type='submit' value='上傳完成,可關閉視窗' onclick='window.close();'></form></div>";
} catch (error) {    
  return error.toString();
}
}

html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
<title>雲端上傳系統</title>
  </head>
<body>
<div id="myForm">  
  <form method="post">
    <h2>雲端上傳系統</h2>
      <input type="text" name="Name" placeholder="請輸入姓名"><br/>
      <input type="text" name="Phone" placeholder="請輸入你的電話"><br/>
      <input type="text" name="Email" placeholder="請輸入你的信箱"><br/>
 <input type="file" name="myFile">
      <input type="submit" value="上傳檔案"
           onclick="this.value='檔案上傳中……';
                    google.script.run.withSuccessHandler(fileUploaded)
                    .uploadFiles(this.parentNode);
                    return false;">
  </form>
</div>
<div id="output"></div>
<script>
    function fileUploaded(status) {
        document.getElementById('myForm').style.display = 'none';
        document.getElementById('output').innerHTML = status;
    }
</script>
</body>
</html>

Rubén
  • 34,714
  • 9
  • 70
  • 166
Steven. Y
  • 31
  • 4
  • 2
    You might want to search through [Tanaike's Answers](https://stackoverflow.com/users/7108653/tanaike) as he has a bunch of answers having to do with upload problems including some that involve the use of filereaders. – Cooper Feb 17 '21 at 16:57
  • 1
    Related [Uploading photo using Google Apps Script](https://stackoverflow.com/q/66053890/1595451) – Rubén Feb 17 '21 at 17:19
  • Hi ! I have tried running your sample code but unfortunately it did not work as it did not even create the file on my Drive. What is stopping you from using the [functional example structure in the documentation](https://developers.google.com/apps-script/guides/html/communication#forms) for forms like yours? – Mateo Randwolf Feb 18 '21 at 10:26

1 Answers1

1

I had the same problem and it came that the new version of GAS has a bug when creating a file with var file = folder.createFile(blob);

Try to disbale the GAS V8 and use legacy.

Alfredo
  • 762
  • 4
  • 16