Base64 Android encode to PHP decode make error

Posted by studio lambda on Stack Overflow See other posts from Stack Overflow or by studio lambda
Published on 2011-11-27T15:17:22Z Indexed on 2011/11/27 17:51 UTC
Read the original article Hit count: 324

Filed under:
|
|
|

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,

© Stack Overflow or respective owner

Related posts about php

Related posts about android