0

I'm trying to create a google form in which I ask people to upload a zip file:

<label for="uploadZip"> Please submit your response in a single zip archive.* </label>
<input type="file" name="uploadZip" required />

In .gs script I tried:

function doGet(e) {
  return template = HtmlService.createHtmlOutputFromFile('form.html');
  return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function uploadFiles(form) {

  try {

    var rootID = "MyRootID";
    var root = DriveApp.getFolderById(rootID);
    var directory = "AllUploadZips";
    var folders = root.getFoldersByName(directory);
    
    if (folders.hasNext()) {
      folder = folders.next();
    } else {
      folder = root.createFolder(directory);
    }

    var foldername = form.myLastName + ", " + form.myFirstName;
    var myFolder = folder.createFolder(foldername);
    var zip = form.uploadZip;
    var file_zip = myFolder.createFile(zip);

  } catch (error) {

    return error.toString();

  }
}

This will save the zip file in "AllUploadZips/myLastName, myFirstName/" in my drive. However the zip is broken with the following error message:

$ unzip myZip.zip
Archive:  myZip.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of myZip.zip or
        myZip.zip.zip, and cannot find myZip.zip.ZIP, period.

The script works fine if I had instead uploaded a .txt or .pdf. It's just having problem with zip files. Does anyone have any idea what's going on? Thanks a lot!

  • Unfortunately, I cannot see your script of Javascript side in your question. So, this is my guess. In your situation, if you are using V8 runtime at the script editor of Google Apps Script, when you disable V8 runtime, what result will you obtain? And also, when you want to use V8 runtime, I think that this thread might be useful. [Ref](https://stackoverflow.com/q/60742695) – Tanaike May 12 '21 at 06:35
  • As I can see you are not invoking the function in this line `var zip = form.uploadZip`, is there missing code we can't see? – Jose Vasquez May 12 '21 at 14:44
  • Thanks Tanaike! Your solution did the magic! – 100253311 May 13 '21 at 15:08
  • Thank you for replying. I'm glad your issue was resolved. From your replying, I flagged this question as the duplicate. – Tanaike May 14 '21 at 01:40

0 Answers0