Uploaded img using GlideSysAttachment but on download shows error
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 03:43 AM
I have tried uploading my img using GlideSysAttachment() into my record and it uploads but when i try to view it - it shows file format not supported.
Please help me understand the fault in uploading process.
Here's my code for writing data into content variable:
upFile.addEventListener('change', attachFiles, false);
function attachFiles(evt){
files = evt.target.files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
filename = file.name;
contentType = file.type;
var fileR = new FileReader();
fileR.onload = (function(file) {
return function(e) {
content = e.target.result;
};
})(file);
fileR.readAsDataURL(file);
}
document.getElementById("submit").disabled = false;
}
Then a glideajax call to call my script include:
function onSubmit()
{
GlideDialogWindow.get().destroy();
alert(content);
var retestga = new GlideAjax("sn_vul.Vulnerability_scripts");
retestga.addParam("sysparm_name", "uploadRetestAttachments1");
retestga.addParam("filename", filename);//filename);
retestga.addParam("contenttype", contentType);//contentType);
retestga.addParam("img_content", content);//window.btoa(content));
retestga.addParam("rec_sysid", '0871095d47175610e451828a516d4342');
retestga.getXMLAnswer(
function(answer) {
alert('answer---');
}
);
return true;
}
and here's the script include :
uploadRetestAttachments1 : function(){
gs.addErrorMessage('hehhhhhhh');
var fileName = this.getParameter('filename');
var contentType = this.getParameter('contenttype');
var content = this.getParameter('img_content');
var itemSysId = this.getParameter('rec_sysid');
gs.addInfoMessage('Processing file: hello- '+fileName +" - "+contentType+content);
if(typeof content =='string'){
var data =content.split(',')[0];
var data1 = content.split(',')[1];
gs.addInfoMessage(data);
gs.addInfoMessage(data1);
var modifiedString = data1.slice(0, data1.indexOf('='));
}
var attachment = new GlideSysAttachment();
var rec = new GlideRecord("sn_vul_pentest_retest");
rec.get(itemSysId);
var resp = attachment.write(rec, fileName, contentType, modifiedString);
gs.addInfoMessage('resp-----'+resp);
return true;
},
I am able to see my encoded string correctly and if I try to decode it using some external online decoders- it works .
Here's the encoded string for reference:
iVBORw0KGgoAAAANSUhEUgAAAAEAAAADCAYAAABS3WWCAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAAAASSURBVBhXY/gPBEwMQAAkGBgAMfsEARoEDOwAAAAASUVORK5CYII=
Actual pic is just one small white dot and my error on download:

0 REPLIES 0