简体   繁体   中英

How do you download folder as .zip using android google drive

I have a folder in my google drive which contains many many docs, and images. I am able to download folder contents by downloading each of the files individually. Through this approach, I listed all the files in my google docs, and just downloaded the one that is docs or images individually.

However this approach is very expensive because it would uses up a lot of api request.

I notice that in a web browser, you can click on a google drive folder and select, save folder as .zip.

So, does anyone know how to download an individual google drive folder as .zip using the android google drive api?

thanks for reading and appreciate any comments or suggestions.

I don't think you can do this with Google Drive API. However, you can use Google Apps Script, although if you are downloading too many or big files, I suggest you not to use this method.

Below is a sample code of how to make zip file stolen from another thread in stackoverflow

var folder = DocsList.getFolder('path/to/folder');
folder.createFile(Utilities.zip(folder.getFiles(), 'newFiles.zip'));

Additionally, it won't work if you have multiple files with the same name in the Folder... Google Drive folders support that, but Zip files do not.

To make this work with multiple files that have the same name:

var folder = DocsList.getFolder('path/to/folder');
var names = {};
folder.createFile(Utilities.zip(folder.getFiles().map(function(f){
  var n = f.getName();
  while (!names[n]) { n = '_' + n }
  names[n] = true;
  return f.getBlob().setName(n);
}), 'newFiles.zip'));

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM