My application requires to upload multiple images to the server. I am sending the image by decoding Base64.
Bitmap bitmapOrg = BitmapFactory.decodeFile(imagePath);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
byte [] ba = bao.toByteArray();
ba1 = Base64.encodeBytes(ba);
And in PHP,
$path = "/".$filename.".jpeg";
$buffer = base64_decode($base);
$handle = fopen($path, 'wb');
$numbytes = fwrite($handle, $buffer);
fclose($handle);
ob_clean();
flush();
Now I can see, some images are only uploaded partially. I can see only the uppermost few bits of the image and all blank in the server. What might be wrong? Are there any drawbacks in using Base64 decoding?
please use this method.i hope its useful to you.In your code,may be image pixel is show so high.then you can't see image in server.
/**
* encodes image to string using Base64
*
* @return String imageString
*/
**
private String prepareImage() {
if (tempPath == null || (!isProfilechanged)) {
return "";
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(tempPath, options);
bitmap = Bitmap.createScaledBitmap(bitmap, 50, 50, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// bitmap.compress(Bitmap.CompressFormat.PNG, 50, baos);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] byteArray = baos.toByteArray();
String imageString = com.qwiches.utils.Base64.encodeBytes(byteArray);
bitmap = null;
System.gc();
Runtime.getRuntime().gc();
return imageString;
}
**