- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:11 AM
I am able to send over text files properly, but I cant send non-text files like images.
Is there any way I can send the contents of an image file over?
Code I am using:
var gsa = new GlideSysAttachment();
var data = gsa.getBytes(attachmentRecord);
//convert to byte array
var dataString = String(Packages.java.lang.String(data));
var byteArray = [];
for (i = 0; i < dataString.length; i++) {
byteArray.push(dataString.charCodeAt(i));
}
//Send byteArray as Payload to external system
E.g. Working example for text files
1) I have a text file containing "HELLO!"
2) The file byte array sent over is [72 69 76 76 79 33 ]
3) File get sent over successfully
E.g. Error for image files
1) I have a image file
2) The file byte array send over is [65533,65533,65533,65533,0,16,74,70,73,70,0,1,1,1,0,96,0,96,0,0,65533,65533,0,67.......many more bytes]
3) Error encounter: There was an error deserializing the object of type System.Byte[]. The value '65533' cannot be parsed as the type 'Byte'.
I suspect that it is because the image contains unrecognized characters like � when trying to convert into the array thereby giving this error. So I would like to know there is anyway to convert an image to a byte array properly on servicenow side?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 07:52 PM
I did not manage to get it to work, so I have to get the external system to provide an API that accepts base64 format instead of file byte array.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:25 AM
HI,
You have to first convert the image into base64 and then use it.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:38 AM
Hi Ashutash,
I did try encoding it in base64 and sending it over, but what I get is that the image did not get sent correctly and is corrupted.
The external system REST API only accepts the FileByte array in decimal format, and not base64 format.
Is that why I am unable to send the image contents over?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2019 12:40 AM
Hi,
We have to check if rest can support image conversion to fie byte or not.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 09:27 AM
I'm experiencing the exact same issue, did you find a solution eventually?