When working on enterprise application, sometimes it is needed to read or write files e.g. writing reports in filesystem. Let’s quickly go through how to read or write files and documents in ONEWEB.
ONEWEB App Designer provides the upload field to attach images and documents to the Smart Form. For more information on Upload Field please check Upload Field. Page Designer currently does not provide any out-of-box fields to add documents to web pages. But users can use a custom JavaScript function to add upload fields to the web pages. Page Designer does support images - both static and dynamic. Page Designer can read an image as a Base64 format string from the database using Microflow and display it on the web page.
For Excel, XML, delimited, or fixed-width files, there is a File Read node to read files in both Process Designer and Microflow. But it does not support images or files and documents in other formats. So, if your application needs to read a file or write a file in the other formats, in Process Designer or Microflow, you can use Java Task to access the file.
The configuration for the Java node is as follows.
Read File You have to write the java code to read the file and convert the byte[] of the file to a string. Define the return value of the function as a string. Now you have to export it as a jar file and upload that jar file to Process Designer or Microflow. Do the mapping of the return value of the function to Process Designer or Microflow also. The sample code is given below.
Java:
Mapping Parameter:
Write File You have to write the java code to write the file. Define the argument value of the function as a string to receive the file and convert that string to byte[], later you can write the byte[] of the file to the path on the server. Now export the jar file and upload that jar file to Process Designer or Microflow. And then do the mapping to pass the argument to the function. The Sample code is given below.
Java:
Mapping Parameter:
Image Files Once the image is encoded to Base64 format, ONEWEB can handle it exactly the same way it does a String. As a result, you can save images to data as well as read images from the database by encoding them to base64 format. To read the image as a base64 encoded string, please refer to the sample below:
Mapping Parameter: