- 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
‎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.