Related to my last article Sending a notification email to Site Administrators by using JavaScript API, we are going to customize alfresco-unzip-action by using the same principles. This addon include one new Share action to unzip inside Alfresco any ZIP file.
Following JavaScript unzips a ZIP file on the same folder (by using the action defined by alfresco-unzip-action). Next, we’ll define a new rule in order to throw this script every time a new document is uploaded to the folder.
unzip.js
function main() { var importer = actions.create("import"); importer.parameters.encoding = "UTF-8"; importer.parameters.destination = document.parent; importer.execute(document); } main();
In order to have this script available in web interface, we need to upload it to scripts folder repository (Data Dictionary > Scripts)
Rule definition
Once our script is available, just choose one site folder and create a new rule by using Run script option and setting:
- When:
- Items are created or enter this folder
- If all criteria are met:
- MIME type for cm:content is ‘ZIP’
- Run action
- Run script ‘unzip.js’
From now, every time a new zip file is uploaded to the folder, its content will be unzipped in the same location.