I am using the following task to upload multiple images from android device to server using php.
@Override
protected String doInBackground(String... params) {
try {
String url = "http://aerialssnip.com/multipleupload.php/";
int i = Integer.parseInt(params[0]);
Bitmap bitmap = decodeFile(map.get(i));
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,
localContext);
sResponse = EntityUtils.getContentCharSet(response.getEntity());
System.out.println("sResponse : " + sResponse);
} catch (Exception e) {
if (dialog.isShowing())
dialog.dismiss();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
return sResponse;
}
The images upload without any error both on the android side and the server side. However, the images uploaded are 0 bytes, they do not have any data and i am unable to view them. php script
<?php
$name = $_POST["name"];
$image = $_POST["IMAGE"];
$decodedImage = base64_decode("$image");
file_put_contents($path,$decodeImage);
?>
Does anyone know what the problem could be in my code? Any help will be appreciated. Thanks in advance.