Help with writeBase64 in GlideSysAttachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 09:14 PM - edited 08-05-2024 10:59 PM
Hi Everyone,
I am trying to send base64 image as attachment to sys_cs_collab_chat table using GlideSysAttachment , but it not attaching and not even returning any error.
Scripted Rest API:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var requestBody = request.body.dataString;
var parser = new global.JSON();
var parsedData = parser.decode(requestBody);
var imageName = parsedData.imageName;
var imageType = "image/jpeg";
var imageValue = parsedData.imageValue;
var table = parsedData.object_name;
var sysId = parsedData.object_id;
var rec = new GlideRecord(table);
rec.addQuery('sys_id', sysId);
rec.query();
if (rec.next()) {
if (imageName && imageValue && imageType != '') {
var sa = new GlideSysAttachment();
sa.writeBase64(rec, imageName, imageType, imageValue);
}
}
})(request, response);
JSON payload;
{"object_id":"ea09239a97d00290c0ebd404a253af08",
"imageName":"QjjeAKNbCwNoJwEKrg1dObUx.jpg",
"imageValue":"<<base64FileContent>>",
"object_name":"sys_cs_collab_chat"}
Can anyone point out my mistake.
cc: @Ankur Bawiskar
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 02:14 AM
did you check in sys_attachment it came fine?
When you download the image from sys_attachment is it a proper one or a corrupted one?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 02:20 AM
Hi @Ankur Bawiskar,
yes, it came fine sys_attachment. I am able to download and I can see it. It is fine.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 03:12 AM
then definitely it's something when you view it in sidebar
can you share screenshot where are you willing to see this?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 03:49 AM
I want the image(attachment) to be visible in sidebar chat as it is there in below image. But that image I have added manually.
I want to make image(attachment) using Scripted Rest API inside sidebar chat. I am able to send text inside sidebar chat using Scripted Rest API, but image is not coming
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 03:52 AM
possibly it won't be direct.
Did you check when you add image manually how it's stored?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader