[Up]: Storage API : Zipped Download

Zipped Download

Script path: /storage/bin/api/zip_download.cgi

Description:  Create a zipped file out of a specified list of files/folders and download it.  The zip-file will be removed immediately after download.

INPUT (via GET or POST)

   json => JSON object input

(Creator's note: Regular way of (flat) parameter input can be made available if need be. Let me know.)

e.g.
{
"sid" : "SID774r7r7737919HyrfsyDCHXj646",
"folder_path" : "/Private/subfolder",
"item_list" : [
"myfolder", "Proposal321.doc", "Camp File 123.xlsx", ...
]
}

WHERE:

sid => the authenticated session id (must be valid)

folder_path => the path to the folder

(Current implementation accepts path to an existing accessible folder only.)

item_list => JSON list of paths

Format of the JSON object is as follows:
{
"item_list" : [ item1, item2, item3 ...]
}

An item can be a sub-folder name, to mean the entire sub-folder will be included in the zip file.


OUTPUT (content-type: text/plain)


   By default the zip file will be temporarily created in the folder_path level, and will be immediately downloaded.
Once download completes, the temporary zip file will be deleted. Some condition may cause the zip file be left
behind, but it can be deleted manually later.

Please check HTTP Response code for sucessful or failure of the HTTP download.
Where there is failure, the HTTP content would be a JSON structured output.

Since the zip file content is immediately returned for general successful case, there is no corresponding successful output,
except for the HTTP Respond code of 200 OK.


JSON output object for general unsuccessful case:

{
"status" : false,
"http_status" : "NNN (status-description)",
"errmsg" : "(reason for failure)"
}

e.g.
{
"status" : false,
"http_status" : "413 Request Entity Too Large",
"errmsg" : "The number of items to zip up exceeds limit."
}


NOTES:

A new zip file will be created in the folder path with a .zip extension.
Its filename will be chosen to be non-existent in the folder_path, taking the following format:

Zip-Content-YYYY-MM-DD-HHMMSS[-N].zip

This filename will be suggested in the return HTTP header:

Content-Disposition: attachment; filename=Zip-Content-YYYY-MM-DD-HHMMSS[-N].zip

In the zip file, the original files' modification date/time will be preserved in the zip file,
but depending on the unzip tool used to extract the files on your client, the timestamp may or
may not be preserved. Windows default unzipping process does not seem to preserve the timestamp,
while 7-Zip tool does.

CONDITIONS:
1) The current disk usage must not be over quota to begin with.
2) Total number of files and subfolders to be zip is limited to 1,000,000 at the moment.
3) The resulting (temporary) zip file size cannot be larger than 1.5 times that of total sizes of all files to be zipped.