Validate base64

Hi!

Is there any way to check the text for encoding, whether it is base64 or not using build-in tools and functions?

Thanks!

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of one module. This is based on this answer Determine if string is in base64 using JavaScript - Stack Overflow

This is just an example. Your final solution may or may not look like this depending on your requirements.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":111,"module":"util:SetVariable2","version":1,"parameters":{},"mapper":{"name":"Is_Valid_Base64","scope":"roundtrip","value":"{{if(length(replace(110.value; \"/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/\"; emptystring)) = 0; true; false)}}"},"metadata":{"designer":{"x":178,"y":-2451}}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

1 Like