Maximum file size to convert to base64 in servicenow

Ramesh R
Tera Contributor

What is the Maximum file size to convert to base64 in servicenow? i tried with 2MB and 3MB but it is not converting to base64. Please help me in this.

21 REPLIES 21

Yes, am getting the output for bytes and size , 

var content64 = GlideStringUtil.base64Encode(bytes);

the above line am getting emptyoutput .

I have one question. The file am using is PDF which has images in the pdf so, is that the problem for not converting base64?

Hi Ramesh,

That should not be an issue

can you update code as below

var StringUtil = new GlideStringUtil();

var content64 = StringUtil.base64Encode(bytes);

gs.info(content64);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, I updated but still same issue. Not getting output

Hi Ramesh,

This script works for me in Global scope for both files under 5MB and greater than 5MB

var gr = new GlideRecord('sys_attachment');
	gr.get('d7ff2c044f96cc90fc11fa218110c746');

	var StringUtil = new GlideStringUtil();
	var gsis = GlideSysAttachmentInputStream(gr.sys_id.toString());
	var ba = new Packages.java.io.ByteArrayOutputStream();
	gsis.writeTo(ba,0,0);
	ba.close();
	var base64EncodedData = StringUtil.base64Encode(ba.toByteArray());
gs.info(base64EncodedData);

Try running this in scheduled job and print in logs; if you try running in scripts

background the instance may get timeout since it is huge data to print

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader