The Now Platform® Washington DC release is live. Watch now!
‎12-26-2019 09:45 AM
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
‎12-26-2019 11:48 AM
Anyone?
‎12-27-2019 03:57 PM
Here are a couple of links that may be able to help you.
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.
‎01-01-2020 12:23 PM
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?
‎01-01-2020 08:44 PM
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.