Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rafaeltoledo
Created May 11, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeltoledo/4f4457ae096ebf021368 to your computer and use it in GitHub Desktop.
Save rafaeltoledo/4f4457ae096ebf021368 to your computer and use it in GitHub Desktop.
Convert Image to Base64
public static String encodeBase64(String path) {
try {
File file = new File(path);
FileInputStream imageInFile = new FileInputStream(file);
byte imageData[] = new byte[(int) file.length()];
imageInFile.read(imageData);
imageInFile.close();
return Base64.encodeToString(imageData, Base64.DEFAULT);
} catch (Exception e) {
Log.e("Base64", "Failed to convert image to Base64", e);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment