How to convert a file to base 64 (like .pdf,.txt) in Android?
android, base64, java
Solution
Try these codes
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");
String encodeFileToBase64Binary = encodeFileToBase64Binary(yourFile);
private static String encodeFileToBase64Binary(File fileName) throws IOException {
byte[] bytes = loadFile(fileName);
byte[] encoded = Base64.encodeBase64(bytes);
String encodedString = new String(encoded);
return encodedString;
}
Problem
How to covert the SD-card documents (.pdf,.txt) to base 64 string and string send to the server