1

I am trying to follow up on the discussion here: Zip drive files.

If you execute the following code, you'll see that for some reason, it produces PDF files. It seems getBlob() is converting them to PDF.

  var folderId = DriveApp.getFoldersByName("Test").getId();
  var files = DriveApp.getFoldersByName("Test").getFiles();
  var blobs = [];
  var fileBlob = '';
  var file = '';
  while(files.hasNext()){
    file = files.next();
    fileBlob = file.getBlob();
    blobs.push(fileBlob);
  }
  
  var zippedFolder = Utilities.zip(blobs, 'Test.zip');
  DriveApp.getFoldersByName("Test").getParents().next().createFile(zippedFolder);

I download Test.zip and every file in that (like a google sheets or google docs) file has been converted into a PDF. Secondly, if the folder contains any Google Forms file, the code with fail with an error saying unable to convert forms to pdf.

I don't want to convert any file to pdf. I just want to zip the folder. Any thoughts?

Community
  • 1
  • 1
Sujay Phadke
  • 2,145
  • 1
  • 22
  • 41

1 Answers1

0

This is the expected behavior when you create a blob from a google apps file with the exception of forms which you have found. There is no way to zip up a native Doc or Sheet without converting it to another format first.

Spencer Easton
  • 5,642
  • 1
  • 16
  • 25
  • Thanks. It sucks though. The native docs files can be individually downloaded and zipped up locally on the computer and uploaded back into drive. I don't see why this couldn't be automated within drive. – Sujay Phadke Mar 29 '16 at 19:44
  • 1
    Hopefully this could help - It looks like files are "defaulted" as PDFs if my understanding regarding the [Blob](https://developers.google.com/apps-script/reference/base/blob#getascontenttype) class is correct. You can specify other mime types when you call the `getAs` method and use that blob instead in your array. – adjuremods Mar 30 '16 at 05:50