How to get binary data of attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2018 07:27 PM
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?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2018 07:56 PM
Hello,
https://snprotips.com/blog/2016/2/25/understanding-and-using-glideattachment
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2018 06:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2018 07:19 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2018 03:05 AM
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()"