I have an app that take video from camera or gallery and convert it into base64 data and that data send to server but the problem is whenever I convert base64 data it will be not correct data in videodata variable. for this I used below code :
FileInputStream objFileIS = null;
try
{
System.out.println("file = >>>> <<<<<" + selectedImagePath);
objFileIS = new FileInputStream(selectedImagePath);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
byte[] byteBufferString = new byte[1024];
try
{
for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;)
{
objByteArrayOS.write(byteBufferString, 0, readNum);
System.out.println("read " + readNum + " bytes,");
}
}
catch (IOException e)
{
e.printStackTrace();
}
videodata = Base64.encodeToString(byteBufferString, Base64.DEFAULT);
Log.d("VideoData**> " , videodata);
Please make it correct...
You can do this with the following code: videodata = Base64.
Convert Files to Base64 Just 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.
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.
When you encode the byteBufferString, you are encoding only the last chunk of data read. You should encode the whole contents of the ByteArrayOutputStream. You can do this with the following code:
videodata = Base64.encodeToString(objByteArrayOS.toByteArray(), Base64.DEFAULT);
However, there is a chance that this may throw an OutOfMemoryError if the video size is big.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With