The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to decompress a GZip string on the server side script include

vkachineni
Kilo Sage
Kilo Sage

Community,

I have a situation where I need to unzip the contents of a Gzip string from attachment_doc table

var strEncodedString1 = 'H4sIAAAAAAAAAA==';
var strEncodedString2 = 'c3RydgEApSAX2wQAAAA=';

//Got the above stings from a REST call to the sys_attachment_doc table. It is a text file with ABCD as content.

var objStringUtil = new GlideStringUtil();
var bytes1 = objStringUtil.base64Decode(strEncodedString1);
var bytes2 = objStringUtil.base64Decode(strEncodedString2);

//This gives a zip string. I would have to decompress it to get the contents as text ABCD
gs.log(bytes1 + bytes2);

I am stuck at the decompressing part.

Looking for suggestions on how to proceed.

Do I need to write a Java class to call the GZIPInputStream to return a decompressed string?

Suggestions please.

Thanks,

vkachineni

 

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022
7 REPLIES 7

vkachineni
Kilo Sage
Kilo Sage

Anyone?

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Here are a couple of links that may be able to help you.

https://community.servicenow.com/community?id=community_question&sys_id=4821cd03db0b3340190dfb243996...

https://community.servicenow.com/community?id=community_question&sys_id=27d7072ddb1cdbc01dcaf3231f96...

For me, those two links helped me to reconstruct and retrieve the base64 encoded multipart gzip file attachment from xml export sets outside of ServiceNow but I figure it might also give you insight on what to do within the ServiceNow platform.

Thanks Chris. From the two links I got the decompress working in a C# class and also a Java class.

I would like to have a solution that is fully coded in ServiceNow.

Is it possible to some how use the Java class and call it from a Script include?

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

I'm not sure if that is accessible any more. But if it is, yes I believe you could call it from a Script Include.

For me, since the sys_attachment_doc contains the sys_id of the attachment on the sys_attachment table I would use the Attachment API to retrieve the metadata and the file content.