How to Convert of bytes to Base64
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
var gsa = new GlideSysAttachment(); var fileBytes = gsa.getBytes( attachment ); var pdfBase64 = GlideStringUtil.base64Encode(file Bytes); //Here i am getting error as: Cannot find default value for object. i am using this code to convert attachment to base64 string conversion, as i need to pass base64 string to external system as it accepts it like that. How to do it for Global scope
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello @KeerthiPraV
//Method#1
var gsa = new GlideSysAttachment();
var fileBytes = gsa.getBytes(attachment);
var pdfBase64 = GlideStringUtil.base64Encode(fileBytes); //your code has a whitespace in the name of this variable
gs.info(pdfBase64);
//Method#2
var gsa = new GlideSysAttachment();
var fileBytes = gsa.getBytes(attachment);
var pdfBase64 = Packages.java.util.Base64.getEncoder().encodeToString(fileBytes);
gs.info(pdfBase64);
Hope that helps!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @KeerthiPraV
In your script, there is space between file and bytes.
You can try with it as well.
var gsa = GlideSysAttachment();
var fileBytes = GlideBase64.encode(gsa.getByte(attachment));
var pdfBase64 = GlideStringUtil.base64Encode(fileBytes);
Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
