Package veryfi

Class Base64Helper

java.lang.Object
veryfi.Base64Helper

public class Base64Helper extends Object
Utility class for Base64 encoding operations.

This class provides helper methods for converting files to Base64 encoded strings that can be used with the Veryfi API. It handles both file paths and File objects, and automatically generates the appropriate data URI prefix based on file extension.

  • Constructor Details

    • Base64Helper

      public Base64Helper()
  • Method Details

    • getBase64FileContent

      public static String getBase64FileContent(String filePath) throws IOException
      Converts a file to Base64 encoded string using the file path.

      This method reads the file from the specified path, encodes it to Base64, and prepends the appropriate data URI prefix based on the file extension.

      Parameters:
      filePath - The path to the file to encode
      Returns:
      Base64 encoded string with data URI prefix
      Throws:
      IOException - if the file cannot be read
    • getBase64FileContent

      public static String getBase64FileContent(File file) throws IOException
      Converts a file to Base64 encoded string using a File object.

      This method reads the file content, encodes it to Base64, and prepends the appropriate data URI prefix based on the file extension.

      Parameters:
      file - The file to encode
      Returns:
      Base64 encoded string with data URI prefix
      Throws:
      IOException - if the file cannot be read
    • getUriPrefix

      public static String getUriPrefix(File file)
      Generates the data URI prefix for a file based on its extension.

      This method determines the MIME type based on the file extension and returns the appropriate data URI prefix. If no extension is found, it defaults to "image/png".

      Parameters:
      file - The file to generate the prefix for
      Returns:
      Data URI prefix string (e.g., "data:image/jpeg;base64,")
    • getFileExtension

      protected static String getFileExtension(File file)
      Extracts the file extension from a File object.

      This method parses the filename to extract the extension (everything after the last dot). If no extension is found or the file has no name, an empty string is returned.

      Parameters:
      file - The file to extract the extension from
      Returns:
      The file extension (without the dot) or empty string if no extension