I am uploading a picture taken by user in Android to my shared hosting using PHP post request. I keep the file path to the picture so I can decode it as Bitmap and then send it to the server.
EDIT: It seems that the issue is coming for the size of the pictures, if I try to upload a photo with size exceeding 800 KB I am getting the following error from the server:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>413 Request Entity Too Large</title>
</head><body>
<h1>Request Entity Too Large</h1>
The requested resource<br />/upload_image.php<br />
does not allow request data with GET requests, or the amount of data provided in
the request exceeds the capacity limit.
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
The Android method:
private void uploadImage() {
Bitmap bitmap = BitmapFactory.decodeFile(CURRENT_PHOTO_PATH);
//Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image);
Log.d("Bitmap processing", "DONE!");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte[] byte_arr = stream.toByteArray();
String image_str = Base64.encodeBytes(byte_arr);
final ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image", image_str));
nameValuePairs.add(new BasicNameValuePair("event_id", Integer
.toString(0)));
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
final String the_string_response = convertResponseToString(response);
Log.d("Image processing", "UPLOADED!");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(UploadImage.this,
"Ready " + the_string_response,
Toast.LENGTH_LONG).show();
}
});
} catch (final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(UploadImage.this,
"ERROR " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
});
System.out.println("Error in http connection "
+ e.toString());
}
}
});
t.start();
}
I wonder how I can solve this problem? Thank you in advance!