0

I use Google Spreadsheet with macro to upload zip files and dump contained data on spreadsheet but it fails in some cases. It seems that there is a file size limit for uploading but I want to know its exact size. Is it described somewhere, hopefully on official document?

When uploading large file it results this on console;

Connection failure due to HTTP 0

And "large file" seems around 9 Mb as I tested with the following generated files;

$ dd if=/dev/urandom bs=8m count=1 of=works
$ dd if=/dev/urandom bs=9m count=1 of=fails

appsscript.json

{
  "timeZone": "Asia/Tokyo",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "sheets": {
    "macros": [{
      "menuName": "showModal",
      "functionName": "showModal"
    }]
  }
}

Code.gs

function showModal() {
  const html = HtmlService.createTemplateFromFile("upload").evaluate();
  SpreadsheetApp.getUi().showModalDialog(html, "Upload file");
}

function uploadFile(e) {
  return `Uploaded: ${e.filename}`;
}

upload.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <form>
      <input type="file" name="file" multiple />
    </form>
  </body>
  <script>
  const elemForm = document.querySelector("form");
  const elemFile = document.querySelector("input[name=file]");
  const handlerFormChange = function(event) {
    event.preventDefault();
    elemFile.disabled = true;
    for (const file of elemFile.files) {
      const fr = new FileReader();
      fr.onload = function(e) {
        const obj = {
          filename: file.name,
          bytes: [...new Int8Array(e.target.result)],
        };
        google.script.run.withSuccessHandler(response => {
          alert(`[SUCCESS] ${response}`);
        })
        .withFailureHandler(response => {
          console.error(response);
          alert(`[FAIL] See console`);
        }).uploadFile(obj);
      };
      fr.readAsArrayBuffer(file);
    }
  };
  elemForm.addEventListener("change", handlerFormChange);
  </script>
</html>

Takuya HARA
  • 499
  • 1
  • 3
  • 17
  • From this answer, in the current stage, it seems that when the data is converted to a Blob, the maximum data size is 50 MB. If you want to retrieve the data from the blob, 50 MB is the maximum size. This might be related to the maximum size of `google.script.run`. But, if you can use the data as the byte array, it seems that a data size of more than 50 MB can be used. [Ref](https://stackoverflow.com/a/60182078/7108653) If this information was not useful, I apologize. But, unfortunately, it seems that this has not been officially published in the official document. – Tanaike Jan 27 '23 at 06:08
  • If you want to upload more size, it is required to upload the data with the resumable upload of Drive API. [Ref](https://developers.google.com/drive/api/guides/manage-uploads#resumable) But, from `to upload zip files and dump contained data on the spreadsheet`, when the file size of the zip file is more than 50 MB, Google Apps Script might not be able to unzip it. Please be careful about this. – Tanaike Jan 27 '23 at 06:11
  • If you can use the data as the byte array, it seems that a data size of more than 50 MB can be used. But, if an error occurs with `google.script.run`, I'm worried that the maximum data size might be 50 MB. – Tanaike Jan 27 '23 at 06:14

0 Answers0