0

I need to upload a file on google drive from a web app. I found on the internet this code which is working for others but not for me since it actually creates the file on Drive but the content is always blank.

The code is this:

    function upload(e) {
  var destination_id = "1AnosRSXyYiOcSLYxBMbjPMEHepHehct6";
  var img = e.myFile;
  var destination = DriveApp.getFolderById(destination_id);
  var createFile = destination.createFile(img);
  return createFile.getUrl();
}

while on client side it is:

 <div>
    <form>
    <input type="file" id="thefile" name="myFile"multiple> 
    <input type="button" value="Upload" id="submitBtn">
    </form>
    </div>

<script>
document.getElementById('submitBtn').addEventListener('click',function(e){google.script.run.withSuccessHandler().upload(this.parentNode)});
<script/>

any idea?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • 1
    Try reverting from v8 to rhino engine. See [tag info page](https://stackoverflow.com/tags/google-apps-script/info) for more details. – TheMaster Mar 09 '20 at 20:17
  • Hello, now it works, thank you for your help! But i wonder why it doesn't with v8. Should it be a bug or does v8 require more code to let it work? –  Mar 09 '20 at 20:26
  • [Search the tags](https://stackoverflow.com/questions/tagged/google-apps-script-web-application+file-upload) – TheMaster Mar 09 '20 at 21:06
  • Does this answer your question? [Uploading binary files broken since yesterday, workaround?](https://stackoverflow.com/questions/60514594/uploading-binary-files-broken-since-yesterday-workaround) – TheMaster Mar 09 '20 at 21:07
  • Star the issue(s) to show support – TheMaster Mar 09 '20 at 21:07

1 Answers1

0

This is issue has been already reported inside Google Issue Tracker.

You can take a look at the issue and mark the +1 to indicate this is affecting to you and help bumping the issue.

Raserhin
  • 2,516
  • 1
  • 10
  • 14