Unzip a Zip File Attachment

I have a requirement to have the user attach a zip file to a case, unzip the file, and continue processing the unzipped files. I have created a Java function in Pega to unzip a file. It has 2 parameters, destDir (destination directory to store the unzip files, and zipFile. First I had zipFile as a String representing the path to the zip file, but I could not figure out how to get the file path from the attachment. We are using Alfresco for out CMIS document management. Then I tried passing the .pyAttachStream of the attachment file, which is a String. In my Java function, I then tried to create a Java File or FileOutputStream from this String. I keep getting an Exception of "File or Directory does not exist". I don't know if I am using a wrong directory path or if something else is wrong. I have attached my Java function, the Activity that calls it, and the error message.

I also have to read the unzipped files back in to another activity for further processing.

Another other approaches? I was hoping that .pyAttachStream would give me a or something that I could just pass to the Java function.

***Moderator Edit-Vidyaranjan: Updated Platform Capability***


Keep up to date on this post and subscribe to comments

August 13, 2019 - 6:23am

September 10, 2019 - 1:56pm

This is what I tried: 

My unzip Java code is:

String strOutputPRFileName = myStepPage.getPage("pyContentStream").getString("pyStream");
String strOutputFileName = myStepPage.getPage("pyContentStream").getString("pyFileName");
ClipboardPage myWorkPage = tools.findPage("pyWorkPage");
//ClipboardPage unZippedFilePage = tools.findPage("UnZippedFilePage");
try {
  PRFile prZipFile = new PRFile(strOutputPRFileName);
  PRInputStream zipPRInputStream = new PRInputStream(prZipFile);
  byte[] buffer = new byte[1024];
  String unzipFileString = ""; zipInputStream = new; unZipInputStr; zipEntry;
  int len;
  while((zipEntry = zipInputStream.getNextEntry()) != null){
    if (!zipEntry.isDirectory()){  
      while((len = > 0){
        unzipFileString = unzipFileString + new String(buffer);
      String fileName = zipEntry.getName();
      myWorkPage.putString("ZipFileName", unzipFileString);
      ParameterPage paramPage = new ParameterPage();
      //unZipInputStr = (;
      //unZippedFilePage.putObject("FileInputStream", unZipInputStr);
      paramPage.putParamValue("fileStream", unzipFileString);

      HashStringMap params = new HashStringMap();
      params.putString("pxObjClass", "Rule-Obj-Activity");
      params.putString("pyClassName", "FBI-Gateway-Work");
      params.putString("pyActivityName", "CreateAttachmentFromZip");
      tools.doActivity(params, null, paramPage);
    //close this ZipEntry
  unzipFileString = "";
  // close last ZipEntry
catch ( e) {

I have attached the CreateAttachmentFromZip activity.

This unzips my attached zip file, and creates new attachments on my Pega case.  However, the XML file that is unzipped has extra blank lines throughout it, and the other unzipped files, which are like a PDF and image file I get "The attachment is not available."

September 10, 2019 - 2:23pm

I also tried setting .pyAttachInputStream to my ZipInputStream in both the Attachment data page and the Drag-Drop data page and for both I get an error in the clipboard of

  • .pyAttachInputStream:Java Object class does not match definition requiring

even though ZipInputStream is a subclass of InputStream. And it did not attach any of the unzipped files.