Issue with base64 image after conversion
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 04:56 AM
Hi,
I have an issue after the base64 string is converted to an image and attached to the incident record. The image is blank. Please find the below screenshot.
Below is the code that i am using:
Client Script - OnChange:
var ajx = new GlideAjax('AttachRec');
ajx.addParam('sysparm_name', 'AttachInc');
ajx.addParam('url', dataURL); // Base64 URL
ajx.addParam('inc', g_form.getUniqueValue()); //incident record sys_id
ajx.getXML(attachImg);
function attachImg(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage("Attachment added successfully and answer: " + answer);
}Script Include:
var AttachRec = Class.create();
AttachRec.prototype = Object.extendsObject(AbstractAjaxProcessor, {
AttachInc: function() {
var incUrl = this.getParameter('url');
var incSysId = this.getParameter('inc').toString();
var base64Bytes = GlideStringUtil.base64DecodeAsBytes(incUrl);
var rec = new GlideRecord('incident');
rec.get(incSysId);
var attachment = new GlideSysAttachment();
var fileName = "newImg.png";
var contentType = '';
var agr = attachment.write(rec, fileName, contentType, base64Bytes);
return attachment.sys_id;
},
type: 'AttachRec'
});Thanks