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

vkachineni
Mega 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

 

 

7 REPLIES 7

vkachineni
Mega Sage

Anyone?

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?

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.