Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a file to Base64?

Tags:

Here the report contain the path(pathname in sdcard in string format)

File dir = Environment.getExternalStorageDirectory(); File yourFile = new File(dir, report); 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; } 

in the byte[] encoded line getting this error. The method encodeBase64(byte[]) is undefined for the type Base64

like image 359
zyonneo Avatar asked Feb 27 '15 05:02

zyonneo


People also ask

Can we convert file to Base64?

Convert Files to Base64Just select your file or drag & drop it below, press the Convert to Base64 button, and you'll get a base64 string. Press a button – get base64. No ads, nonsense, or garbage. The input file can also be an mp3 or mp4.

How do I convert a text file to Base64?

How to convert string to Base64 online. Type or paste your text in the “Text” field. Press the “Encode Text to Base64” button. Copy or download the result from the “Base64” field.

How do I decode a file in Base64?

To decode a file with contents that are base64 encoded, you simply provide the path of the file with the --decode flag. As with encoding files, the output will be a very long string of the original file. You may want to output stdout directly to a file.


1 Answers

String value = Base64.encodeToString(bytes, Base64.DEFAULT); 

But you can directly convert it in to String .Hope this will work for you.

like image 91
Sajith Vijesekara Avatar answered Sep 18 '22 18:09

Sajith Vijesekara