Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Read an image file using a file listener



User needs to configure a file listener to read an image and attache it to a newly created work object

Queries are as follows:
Can the user get the properties needed from the LogServiceFile page,
How do we read the image stream and encode it in base64 encoding so that i can set it to the pyAttachStream property of the Data-WorkAttach-File class page.
User has a code that reads this stream using methods form commons-codec-1.5.jar but this is not available in 6.1sp2 and there is a security concern so he has to use any of the jars existing in prpc6.1 sp2.
So what code should he use to read the file stream and encode it to base 64 format and set the clipboard property pyAttachStream.


Below are the steps to read the file and stores the base64 encoded stream to a string propety.

1. Use any page for "Page name" field on 
Service tab of Service File rule form(For ex. fileListenerPage of your work class).
2. Use “File at a time” for Processing Mode and “text only” for Data Mode fields on Method tab. Set Character Encoding to UTF-8.
3. Map the file stream to any text clipboard property(For example fileListenerPage .test).
4. In the Service Activity add a Java step and use below code.

       inByteStream = new"fileListenerPage").getString("test").getBytes(java.nio.charset.StandardCharsets.UTF_8));
       inStream = new;
       outByteStream = new;
       outStream = new;
       encStream = Base64Util.encode(outStream);
       doStream = new;
                byte[] buffer2 = new byte[4096];
                int len;
                while(( len = != -1)
                                doStream.write(buffer2, 0, len);             
                strFileData = outByteStream.toString(); // This sets the strem to a string property.
          //      ClipboardPage cpNFAttach = tools.findPage("AFilePage", false);
              //  cpNFAttach.putString("pyAttachStream", strFileData);
                // close the fos and delete the file
                // fileName.delete();
catch (Exception e)

Published January 31, 2016 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us