Let’s say, you want to allow users to drop a .zip file containing a structure, with folders, subfolders, and files, such that once this zip file has been uploaded, instead of creating a
File document storing the .zip file, it actually creates the files, with their hierarchy, like this:
If you need this feature, we have just the right plugin for you: nuxeo-unzip-file(1).
Once installed, the plugin allows you to precisely do what is described above: Have a .zip file containing a hierarchy of files, import it in your Nuxeo application, and it will automatically extract the files and create the exact same hierarchy.
Now, maybe you want more granularity in your application. Maybe sometime the user wants to create the documents and sometime they want to just store the zip file (typically in a
For this purpose, you must: - Disable the automatic behavior - Handle the extraction of the file “on demand”
These two points can be achieved using our wonderful and amazing Nuxeo Studio online configuration tool.
To disable the automatic behavior, you must override the default contribution the plugin adds to the
FileManager service. So, in Studio, go to Advanced Settings > XML Extensions and create a new one. Name it whatever you want and paste the following XML, where we just use the exact name of the contribution, but disable it:
<extension target="org.nuxeo.ecm.platform.filemanager.service.FileManagerService" point="plugins"><plugin name="UnzipToDocuments" <strong="">enabled="false"</plugin>></extension>
Now, if you deploy your changes and you drop your .zip file, the Nuxeo Platform will create a
To extract “on demand” you will use an operation provided by the plugin,
Document.UnzipFileToDocuments. This operation accepts either a
Document or a
Blob. When the input is a Document, it will use its
file:content field to get the blob (you can use the optional
xpath parameter to specify another field). By default, it will create the documents in the current container, but the operation also allows you to set a
target parameter if you prefer. So you basically just call the operation when you need (maybe in an event handler, maybe by providing a button in the UI, etc.).
(1) This plugin is brought to you by your awesome Nuxeo Solutions Architects team, where each of us added the feature we needed (so one of us started it and built the extraction, one of us added optional parameters, one of us added unit tests, fixed bugs, etc. Pure teamwork!)