convert zip file to base64

Working with Webmethods 9.7 - Linux

Hello, really looking for some help here.

Can someone tell me how to convert a big 15 MB gzip file to a base64 encoded file?

I think what needs to happen is:

  • place the file somewhere in the unix filesystem and get the file (pub.file:getFile)
  • convert bytes to stream
  • convert stream to base64
  • save base64 to file

Am I on the right track? Shorter/better way to do it? Definitely hoping this won’t involve having to create special java code, but please let me know.

I really appreciate the help! Thanks

Hi Joe,

referring to the IntegrationServer´s Build-In-Services Guide:

pub.file:getFile (loadAs = bytes)
pub.string:base64Encode (bytes = body/bytes)
pub.file:stringToFile (data = value)

Make sure you have configured the fileAccessControl.cnf in WmPublic/config accordingly and reloaded the package afterwards.

Regards,
Holger

Thank you very much for the reply Holger. One more question though: I mentioned “stream” in my original question, because I thought that for very big files, “stream” had to be utilized when doing the conversion. Is your answer saying that this is not true and I should be able to utilize your answer regardless if the compressed file is gigantic (15 - 20 MB for instance)?

Thanks again

JoeG,

I would suggest loadAs = stream (for loading or extracting large file content) and down stream follow the steps that Holger mentioned and see if this makes a difference processing wise and make sure you drop the vars appropriately.

HTH,
RMG

Joe,

You’re right. For very big files, you should consider using streams instead of byte arrays. Now, whether 15MB is a really big file in today’s terms can be debated. It may be possible for you handle a file of that size as a byte array depending on how much memory you have and what else you have going on in your server at the time.

If you want to play it safe though, which I can certainly appreciate, you will likely have to create your own Java service(s) to base-64 encode a stream. Luckily, some of the hard work has been done for you already. Take a look at https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64OutputStream.html

It looks like Java 8 may have also come out with some support for this out-of-the-box: https://docs.oracle.com/javase/8/docs/api/java/util/Base64.Encoder.html

Percio