- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 04:58 PM
I've created a custom upload attachment UI page and it will pass the file to a ajax function to upload. If upload a normal file with 100kb it working fine. but if upload a 3 MB file, script include will return null value.
Is there a limit on how much data size a glide ajax can accept?
UI Page Client Script
function uploadFormData(files) {
document.getElementById("ddArea").classList.add("d-none");
document.getElementById("loading").classList.remove("d-none");
document.getElementById("loading").classList.add("d-block");
fileCount = 0;
fileLength = files.length;
for (var i = 0; i < files.length; i++) {
var reader = new FileReader();
reader.filename = files[i].name;
reader.filetype = files[i].type;
// Create an event listener to trigger Ajax funciton after file is read
reader.onloadend = function(e) {
var ga = new GlideAjax('utilCredit');
ga.addParam('sysparm_name', 'uploadAttachment');
ga.addParam('sysparm_filename', e.target.filename);
ga.addParam('sysparm_filetype', e.target.filetype);
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
ga.addParam('sysparm_file', e.target.result.toString());
ga.getXMLAnswer(getResponse);
};
reader.readAsDataURL(files[i]);
}
}
function getResponse(response) {
fileCount++;
if (fileCount == fileLength) {
location.reload();
}
}
Server Side Script Include
//Create Attachment Doc and Upload Attachment
uploadAttachment: function() {
try {
var file = this.getParameter('sysparm_file');
var filename = this.getParameter('sysparm_filename');
var filetype = this.getParameter('sysparm_filetype');
var sys_id = this.getParameter('sysparm_sys_id');
var gr = new GlideRecord('x_ytlcb_credit_a_0_credit_attachment_doc');
gr.credit_application = sys_id;
var sysId = gr.insert();
var gsa = new GlideSysAttachment();
var base64String = file.substr(file.indexOf("base64,"), file.length - 1).replace("base64,", "");
var attachmentId = gsa.writeBase64(gr, filename, filetype, base64String);
gr.file_upload = attachmentId;
gr.update();
var gra = new GlideRecord("sys_attachment");
gra.addQuery("table_name", 'x_ytlcb_credit_a_0_credit_attachment_doc');
gra.addQuery("table_sys_id", sysId);
gra.query();
if (gra.next()) {
gra.table_name = "ZZ_YYx_ytlcb_credit_a_0_credit_attachment_doc";
gra.update();
new global.VariableUtil().copy(gra.sys_id, 'x_ytlcb_credit_a_0_credit_attachment_doc', sysId);
}
} catch (err) {
return err.message;
}
return gr.sys_id;
},
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 06:54 PM
Hi Michael,
I don't think GlideAjax() is meant to send attachment files. Use Attachment API with streaming instead to process large files.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 06:54 PM
Hi Michael,
I don't think GlideAjax() is meant to send attachment files. Use Attachment API with streaming instead to process large files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 04:21 PM
Hi Hitoshi,
Thanks for the help. Manage to get it work using scripted REST API.