Writing output to disk in OL Connect Automate
In OL Connect Automate, saving the output from the all in one and paginated output to disk can be handled using various techniques. This tutorial outlines the following methods to achieve this using OL Connect Automate:
- Handle it through OL Connect’s output engine
- Write the default zip output
- Download individual files from OL Connect’s File Store
- Unzipping the default zip archive and write individual files
The downloadable sample flows can be found at the bottom of the article.
Set up the output location in the Output Preset
The easiest method is to set the output location directly in the Output Preset. This directs the OL Connect Server to save the files to the specified location based on the Job Output Folder and Job Output Mask options defined in the preset or to send the output directly to a printer. For instructions on setting this up in the Output Preset, refer to the Output Options section in the online help of OL Connect.


Changing the Output Folder option to a static value or a msg property overwrites the value specified in the Output Preset. This makes it easier to move the flow to different environments like Development, Testing, Acceptance, and Production (DTAP).

Write the default zip output
By default, both the all in one and paginated output nodes return the output from the OL Connect’s File Store to the flow as a zip file (data), which is stored in msg.payload. To save this zip file to disk:
- Add write file node immediately after the all in one or paginated output nodes. Make sure the Output Option of the these nodes is set to Zip file in msg.payload.
- Set the target location in the Filename property of the write file node.


Downloading files from the File Store
Instead of downloading the entire zip file, individual files can be retrieved from the OL Connect File Store (one or more, depending on the Output Preset configuration). Here’s how to download and save files one by one:
- Change Output Options in the Properties panel of the all in one or paginated output nodes to File list in msg.payload.
This returns an array of output files names and the managed file ID of the print job. Concatenating these values files to be downloaded from the File Store one by one.
- Add a split node to iterate (loop) over the file list array.
- Connect a change node and configure the following rules:
- msg.managedFileId Add a rule to append the name of the file (stored in msg.payload) to the msg.managedFileId separated by a forward slash using a J expression (JSONata).
- msg.outputPath Add a rule to specify the target location for the file by appending the name of the file (stored in msg.payload) to folder location using a J expression (JSONata).
- Add a file download node to retrieve the file from OL Connect’s File Store
- Use the write file node to save the downloaded file to disk. Set the Filename option to the value of msg.outputPath set in step 3.


Note! The JSONata expression language is used to format, rearrange, and combine data. Checkout the jsonata.org website for more information.
Unzipping and writing files
If working with individual files from the zip output is necessary, the zip file returned by the all in one and paginated output nodes can be unzipped using a third-party node. To unzip using a third-party node, follow these steps:
- Install the node-red-contrib-zip package from the Manage palette option in the top right menu. This node enables creating and reading zip files.
- Add the decompress node after the all in one or paginaged output node. This will unpack the archive and returns an array with objects containing the filename as a string and
payloadas a buffer. - Add a split node to iterate over the array.
- Use a change node to set msg.payload to file data and set msg.filename to the file name. See the image below.
- Add a write file node to save each file to disk.


Conclusion
These techniques provide flexibility in managing the output of OL Connect’s all in one and paginated output nodes in OL Connect Automate. Choose the method that best fits your workflow needs to efficiently save the output to disk.
Download the sample flows: writing-output-to-disk.json