How to convert source Image into base64 format in Servicenow

Ratan B
Tera Contributor

Hi Community, 

 

When I get the value of HTML field am getting below pasted HTML format data, but the requirement is to convert the source images which am getting from the field value into Base64 format.

<p><img style="align: baseline;" title="" src="test.pngx" alt="" width="633" height="137" align="baseline" border="" hspace="" vspace="" /></p>
<p><img src="/sys_attachment.do?sys_id&#61;7dc290161b5f1110292b859e7b4bcb61" /></p>
<p> </p>

 

Thanks in advance.

 

3 REPLIES 3

ersureshbe
Giga Sage
Giga Sage

Hi, can you use below link for your requirement.

http://www.john-james-andersen.com/blog/service-now/easy-base64-encoding-in-servicenow.html

 

Regards,
Suresh.

ChrisBurks
Mega Sage

From the HTML markup it looks like it's pointed to an attachment.

One way to this is parse out the sys_id from "src" attribute of the "img" element. Pass that sys_id server-side and use the "GlideSysAttachment" class to get the image in base64 format.

Note: You would also need the table name of where the attachment is attached.
Reference: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideSysAttachme...

 

I could give you more of an example but I'm not sure where you're trying to do this from; Portal, UI Page, etc.

alexaria
Tera Contributor

got similar issue with this html <img> part. i have a html previously someone else created as below (base64 db image storage i guess):

<p><img src="blob:https://..../afc6cdbb-...-96fd397c4f4e" alt="" /></p>

but as soon as I open then close(save) the source code window in html editor, it auto turns to attachment as below:

<p><img src="/sys_attachment.do?sys_id&#61;7dc29...b61" /></p>

WHY? HOW to avoid it? 

Issue: it blanks out images on public pages as our attachments are not open to public view.