Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Attachment compression issue when uploading certificate files via REST API

ShreeChandR
ServiceNow Employee
ServiceNow Employee

I am uploading a .p12 certificate file to my ServiceNow instance using the Attachment REST API (`/api/now/attachment/file`).
After upload, the file seems to be compressed or altered.
I want the uploaded file to remain exactly as the original binary (.p12), without any compression.

API: <instace-url>/api/now/attachment/file?table_name=sys_certificate&table_sys_id=348aaf8be864721098749d201822a4c0&file_name=keystore.p12
-f file: <file>

- ServiceNow version: zurich

- File type: .p12 (PKCS#12 certificate)

- Uploading to table: sys_certificate

- size of keystore.p12 file is 3kb



1 REPLY 1

kaushal_snow
Giga Sage

@ShreeChandR ,

 

It's important to note that ServiceNow may automatically compress or encode binary files like .p12 during the upload process, potentially altering the file's integrity. To mitigate this, ensure that the Content type header is set to application/octet-stream to indicate that the file is binary. ....Additionally, avoid manually Base64 encoding the file, as ServiceNow handles encoding internally..... If the file still appears corrupted after upload, consider using a Scripted REST API to handle the file upload, which can provide more control over the process and reduce the likelihood of automatic compression or encoding..... Alternatively, uploading the file directly through the ServiceNow UI may bypass these issues. For more advanced scenarios, utilizing the saveResponseBodyAsAttachment() method in a RESTMessageV2 script can simplify the process of saving binary files directly to records without manual encoding....

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/