Skip to Content

It’s possible that in some scenarios you should compress  as a ZIP and send a document through  a WebService in base64. For achieve this we can use UDF and some libraries.

The UDF will be this:


public String invoice2zip(String invoice, String filename, Container container) throws StreamTransformationException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos); 
 BASE64Encoder encoder = new BASE64Encoder();
String encoded = "";
try{
     zos.putNextEntry(new ZipEntry(filename)); 
    zos.write(invoice.getBytes());
     zos.close();
      encoded = encoder.encode( baos.toByteArray());
}catch(Exception e){
return "";
}
     return encoded;
}

We need to import a library for Base64 encoding:  sun.misc.BASE64Encoder

Mapping:

mapping.PNG

UDF:

/wp-content/uploads/2014/07/test_490640.png

Regards

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

    1. Evgeniy Kolmakov

      Hi Narayana!

      And what’s the problem with this? Just do the same in reverse order: decode your Base64 string into byte array containing your zipped content and unzip it.

      Regards, Evgeniy.

      (0) 

Leave a Reply