Base64 Android encode to PHP decode make error
- by studio lambda
I'm a french guy, so, I'm sorry for my english...
I'm developing an Android App which communicate with a PHP REST service. So, when I try to encode an image file into Base64 like this :
InputStream fileInputStream = context.getContentResolver().openInputStream(uri);
BufferedInputStream in = new BufferedInputStream(fileInputStream);
StringWriter out = new StringWriter();
int b;
while ((b = in.read()) != -1)
out.write(b);
out.flush();
out.close();
in.close();
String encoded = new String(android.util.Base64.encode(out.toString()
.getBytes(), android.util.Base64.DEFAULT));
On server side, I make :
$data=base64_decode(chunk_split($base64BinaryData));
The result is that my image file is corrupted!
INFO : the image is made by an Intent to android.provider.MediaStore.ACTION_IMAGE_CAPTURE Activity in Emulator mode (avd 5554)
I've already read lots of discussions about similar problem but nothing fix my bug.
thanks for help
Regards,