Convert large file into base64 in scope application

RameshwarK
Tera Contributor

Hello,

I am facing issue in rest API, where i need to send request record details with attachment to 3rd party. Attachment needs to send in base64 format. I am able to send attachment if file size less then 5 MB, but if file size is greater the 5 MB payload send empty key. I can't use GlideStringUtil() as this rest API is in scope application. How we can send large file in base64 format in scope application?

 

Appreciate your help!!!!

 

Thanks

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@RameshwarK 

this should give you base64 of file more than 5MB in global scope, create script include in global scope, accessible from all scopes and then call it from your scoped app script

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);

You can increase the property "com.glide.attachment.max_get_size" so that it works for more than 5MB in scoped app, but it's not recommended

see these links for some workaround

Why is GlideSysAttachment.getContentBase64() documented, but not defined? 

Has anyone increased com.glide.attachment.max_get_size? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@RameshwarK 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur,

Thanks for response.

Code that you pasted is work in global but for my scenario rest api is in scope. if we talk about increasing attachment max size in system property but still not working.

Do we have any alternative for getContentBase64() method for scope application which support files with more then 5 MB size?

Thanks

@RameshwarK

I already informed the workaround

create script include in global scope, accessible from all scopes and then call it from your scoped app script

Did you check the other links which talks about scoped app workaround? I haven't tried it though.

If my response helped please mark it correct , helpful 👍 & close the thread so that it benefits future readers.

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