I want to do the following:
a) zip all files inside a folder which is defined by its folder Id and return the FileId of the zipped archive
b) Create a download link from the zip's File Id so i can embed the link into my Html template so i can let users (with the right permissions to the shared drive where the .zip file is stored) download it by clicking on the link.
Now i am stuck with a)
My code so far is derived from this post: Creating a zip file inside Google Drive with Apps Script
But it seems like some of the solutions there are deprecated (f.ex. DocsList). As i could not find up-to-date solutions from the recent 2 years that work for me i thought that it is worth to look now into the zipping case.
/*****
*** This Function returns all blobs from a folder
*/
function getBlobs(folderId) {
let blobs = [];
folder = DriveApp.getFolderById(folderId)
let files = folder.getFiles();
while (files.hasNext()) {
let file = files.next().getBlob();
blobs.push(file);
return blobs;
}
}
/*****
*** This Function zips all blobs in a folder and returns the zip file ID
*/
function zipFilesInFolder(blobs, filename) {
let zip = Utilities.zip(blobs, filename + '.zip');
zipFileId = zip.getId()
Logger.log("{zipFilesInFolder} [zipFileId]: " + zipFileId)
return zipFileId;
}
filename = "myzip"
folderId = "123456789a94..."
blobs = getBlobs(folderId)
zipFileId = zipFilesInFolder(blobs, filename)