How to encode base 64 code in apex?

How to encode base 64 code in apex?

Salesforce.com makes it pretty easy to perform Base-64 encoding in Apex via their EncodingUtil class. Below is an Apex code snippet with a very simple example of the base-64 encode/decode. You can refer to EncodingUtil documentation here for more information.

How to get Base64 string from binary string?

When I try to use readAsDataURL, It breaks javascript and does not call apex function. You can’t start with a UTF-8 string in Apex; by then, the damage has already been done by UTF-8 string conversion. Instead, use FileReader readAsDataURL to get a base-64 encoded version of the file, then send that directly to Apex.

When do you use Base64 to encode data?

Base64 encode your data without hassles or decode it into a human-readable format. Base64 encoding schemes are commonly used when there is a need to encode binary data, especially when that data needs to be stored and transferred over media that are designed to deal with text.

How to get Base64 string from UTF-8 string?

You can’t start with a UTF-8 string in Apex; by then, the damage has already been done by UTF-8 string conversion. Instead, use FileReader readAsDataURL to get a base-64 encoded version of the file, then send that directly to Apex.

Are there any characters in the base64 encoding?

Base64 encoding uses the characters [A-Za-z0-9+/]. The backslash and quote characters shown here are not part of the Base64 encoding but the JSON wrapper around it. You need to deserialize the JSON first, into a String, and then Base64-decode that String:

Where is unrecognized Base64 character in stringexception?

Class.TestUpdateCourseCompletionStatusService.testupdate: line 30, column 1. Thanks in Advance. You can’t directly decode a plain string. Any String should be encoded first to decode, so in your case it is getting unrecognized character on line 28 of your UpdateCourseCompletionStatusService class.

How to send a Base64 image in HTML email?

Send a base64 image in HTML email. Using a rich-text editor, our users can drag and drop a saved image from their desktop to the editor. The image appears and displays properly in the web page after they submit. Since the image is not uploaded anywhere, the editor saves the image as a base64-encoded image.

Can you use a Base64 image in AOP?

In an AOP Template, you can use a tag {%image} and AOP will replace that tag with a base64 encoded image. This works great when you open the resulting HTML file in a browser, but when using emails it’s not so great as some email clients don’t support base64 encoded images e.g. Outlook.

How to use apex office print for email?

Some people use APEX Office Print (AOP) to send out HTML emails based on a custom HTML template they created. Today we got a question in our AOP support inbox how to include images in those emails. In an AOP Template, you can use a tag {%image} and AOP will replace that tag with a base64 encoded image.