How to get binary data of attachment?

PhoenixMing0912
Giga Expert

Hi all,

There is a sample coding which is from service now document.

var attachment_sys_id = 'bacd7034dbeaa3403aff6a4948964f28';
attachmentStream = new GlideSysAttachmentInputStream(attachment_sys_id);

However, attachmentStream is just something like "[B@89e840" but I want the real binary data.

I have read through documents but I didn' t find the answer.

Can anyone help me out?

15 REPLIES 15

Deepak Ingale1
Mega Sage

Hello,

 

https://snprotips.com/blog/2016/2/25/understanding-and-using-glideattachment

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

Above two links will help you to understand binary and base64 of attachment.

 

Note: Please mark reply as correct/helpful if it answers your question

Hi there,
Thanks for the reply.
I have read the links you offered.
First, GlideSysAttachment.
getBytes() is not officailly documented and second even I got the birnary of attachment, when I call the external service, this binary didn't work.
I have tried other ways like Java call by using the same attachment and it worked.
So I think the binary I got in service now script was not correct.

 

You are correct, its in bytes format I believe which you get via GlideSysAttachment API. 

 

If you want to retrieve the attachment as binary, you need to make a REST API call via attachment API

 

https://docs.servicenow.com/integrate/inbound_rest/reference/r_AttachmentAPI-GETidFile.html

 

Even if you want to make this binary available inside ServiceNow at Server Side, you can make the call to above API from Server Side script and get the binary of attachment. 

 

Note: Please mark reply as correct if it answers your question.

Attachment REST API works, however, the binary I got from the API is not accepted for third-party service either.

I think what I got is the same as "GlideSysAttachment.getBytes()"